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

Shahrooz Kia
  • 89
  • 2
  • 14
  • two things - 1) have you tried logging into SQL Server (manually) with those credentials? does it work? 2) why are you manually executing SQL against the membership schema? Is there logic you require which is not covered by the Membership API? `Membership.GetUser()` not sufficient? – RPM1984 Oct 19 '10 at 08:31

1 Answers1

1

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 Sanchez
  • 6,079
  • 3
  • 24
  • 31