我有一个使用IIS设置的本地测试环境。我正在使用下面的连接字符串使用我的Windows身份验证在ASPX页面的代码隐藏中连接c#。我收到[PCNAME] / ASPNET登录失败的错误。当我指定连接字符串使用登录时,为什么用户名ASPNET尝试登录?
user id=[UID];password=[PASS];server=[LOCALSERVER];database=db_specialOps;Trusted_Connection=yes
答案 0 :(得分:3)
受信任的身份验证使用正在执行该过程的用户的凭据。如果指定为yes,则忽略连接字符串中的用户名和密码。
在这种情况下,ASPNET用户帐户是运行该进程的用户,因此这是用于连接到SQL Server的帐户。
检查,另一个SO问题解决了这个问题。
When using Trusted_Connection=true and SQL Server authentication, will this effect performance?
答案 1 :(得分:0)
删除连接字符串的Trusted_Connection=yes
部分。它告诉sql客户端库使用Windows身份验证连接到sql server,并使用当前进程的Windows身份。在ASP.NET案例中[PCNAME]/ASPNET
。这就是你看到错误信息的原因。
如果您想使用sql auth,只需提供用户名和密码 - 不需要Trusted_Connection=yes
部分。
答案 2 :(得分:0)
Windows身份验证的连接字符串:
connectionString="Server=MyServer;Database=MyDb;Trusted_Connection=Yes"
OR
connectionString="Initial Catalog=MyDb;Data Source=MyServer;Integrated Security=SSPI;"
没有用户/传递
使用user / pass
进行SQL身份验证的连接字符串connectionString="Server=MyServer; Database=pubs; User Id=MyUser; password= P@ssw0rd"
providerName="System.Data.SqlClient"
另见这个问题,可能对您有所帮助: Connect to SQL Server using windows authentication and specific account