我正在尝试使用SqlDependency创建一个示例SignalR应用程序。我使用带有sysadmin角色的sysadmin帐户。我正在编写以下代码:
using (SqlCommand command = new SqlCommand(query, connection))
{
command.Notification = null;
DataTable dt = new DataTable();
SqlDependency dependency = new SqlDependency(command);
SqlDependency.Start(connection.ConnectionString);
//dependency.OnChange += dependency_OnChange;
if (connection.State == ConnectionState.Closed)
connection.Open();
var reader = command.ExecuteReader();
}问题是,当执行下一行时,
SqlDependency.Start(connection.ConnectionString);我知道错误:
用户“sa”登录失败
当我注释它并正常加载数据时,相同的代码工作正常(不依赖)。我也可以登录管理工作室帐户,使用这些凭据。
发布于 2015-04-16 13:09:06
问题在于你的ConnectionString。它在您的web.config文件中,可能包含如下内容:
<connectionStrings>
<add name="ConnectionStringName" connectionString="Data Source=YourSqlServerName;Initial Catalog=YourDataBaseName;User ID=sa;Password=YourPassword" providerName="System.Data.SqlClient"/>
</connectionStrings>在收到此错误后,我假设您使用了Server身份验证,因为对于Windows身份验证,您不必指定用户ID和通过。因此,我建议您打开Managment,并尝试连接来自您的ConnectionString的设置:服务器名、登录--在您的示例中是"sa“和密码。可能是你的用户/密码出了问题。
发布于 2018-04-08 10:35:04
原因是该连接对象在初始化连接后会丢失密码。添加Yourconnectionsting.PersistSecurityInfo = True
https://stackoverflow.com/questions/28149692
复制相似问题