For some reason this connection string is working with node js and this is an application user:
var http = require("http");
const sql = require("mssql");
const port =3333;
sql.connect('Server=B-SG-SQ;Database=DevTest;User Id=sg\\DevtestB;Password=DevtestB123;Encrypt=true;trustServerCertificate=true')
.then((conn) => {
console.log(conn);
console.log("MSSQL: connected");
conn.query(`select * from samples`)
.then(data => console.log(data))
.then(() => conn.close())
}).catch(err => { console.log("err " + err) });
And I can see the list of objects from my table.
But when I try it with an ASP.NET Core 7 Web API:
public class DataContext
{
private readonly DbSettings _dbSettings;
public DataContext(IOptions<DbSettings> dbSettings)
{
_dbSettings = dbSettings.Value;
}
public IDbConnection CreateConnection()
{
var connectionString = "Server=B-SG-SQ;Database=DevTest;User Id=sg\\DevtestB;Password=DevtestB123;Encrypt=true;TrustServerCertificate=true";
return new SqlConnection(connectionString);
}
}
This is the result that I see:
Login failed for user 'sg\DevtestB'
2条答案
按热度按时间ql3eal8s1#
when you use user domain ,you didn't need to use password sample connection string:
you can Test connection with udl file
Test Test connection: Test connection with udl
nzk0hqpo2#
Impersonation Middleware in an Asp.Net Core Intranet app for Windows-Identity
and https://learn.microsoft.com/en-us/dotnet/api/system.security.principal.windowsidentity.runimpersonated?view=net-7.0
It worked. But i had to change the code in the middleware to: