[英]how to connect directly to aspnetdb database
我想连接到aspnetdb,但会出错,提示“用户登录失败”,这是Web配置中的连接字符串:
<add name="UserProfiles" connectionString="Data Source=KIA;Initial Catalog=aspnetdb;Integrated Security=True;"
providerName="System.Data.SqlClient" />
这是我的代码:
SqlConnection connection = new SqlConnection();
SqlCommand ComNewCheckSum = new SqlCommand();
connection.ConnectionString = ConfigurationManager.ConnectionStrings["UserProfiles"].ConnectionString;
connection.Open();
ComNewCheckSum.Connection = connection;
ComNewCheckSum.CommandText = String.Format("select UserID from aspnet_Users where UserName = {0}", _UserName);
return Convert.ToInt32(ComNewCheckSum.ExecuteScalar());
我如何克服错误? 谢谢
在连接字符串中,您使用的是“ Integrated Security = True”,这意味着您尝试使用Windows凭据连接到该数据库,这似乎不利于访问该数据库。
尝试使用您知道可以访问此数据库的用户和密码并更新您的连接字符串,以便它使用该信息-例如:
<add name="UserProfiles" connectionString="Data Source=KIA;Initial Catalog=aspnetdb;User ID=someuser;Password=somepassword;"
providerName="System.Data.SqlClient" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.