开发者

how to connect directly to aspnetdb database

I wanna connect to aspnetdb but it makes an error says "Login failed for user" this is the connection string in web 开发者_开发技巧config :

<add name="UserProfiles" connectionString="Data Source=KIA;Initial Catalog=aspnetdb;Integrated Security=True;"
   providerName="System.Data.SqlClient" />

and this is my code:

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

how can i pass through error? thank


In your connection string you are using "Integrated Security=True", which means you are trying to connect to this database using your Windows credentials which it seems aren't good to access this database.

Try using a user and password that you know have access to this database and update your connections string so it uses that information - example:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜