【问题标题】:how to connect directly to aspnetdb database如何直接连接到aspnetdb数据库
【发布时间】:2010-10-19 08:21:36
【问题描述】:

我想连接到 aspnetdb,但出现错误提示“用户登录失败” 这是网络配置中的连接字符串:

<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());

我怎样才能通过错误?谢谢

【问题讨论】:

  • 两件事 - 1) 您是否尝试过使用这些凭据(手动)登录 SQL Server?它有效吗? 2) 为什么要针对成员模式手动执行 SQL?您是否需要 Membership API 未涵盖的逻辑? Membership.GetUser() 不够?

标签: asp.net sql database asp.net-membership database-connection


【解决方案1】:

在您的连接字符串中,您使用的是“Integrated Security=True”,这意味着您正在尝试使用您的 Windows 凭据连接到该数据库,而访问该数据库似乎并不好。

尝试使用您知道可以访问此数据库的用户和密码并更新您的连接字符串,以便它使用该信息 - 示例:

<add name="UserProfiles" connectionString="Data Source=KIA;Initial Catalog=aspnetdb;User ID=someuser;Password=somepassword;"
   providerName="System.Data.SqlClient" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-02
    相关资源
    最近更新 更多