views:

10

answers:

1

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

A: 

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" />
Ricardo