unable to connect login failed for user

Posted by Parthibansk under Sql Server on 8/16/2012 | Points: 10 | Views : 4240 | Status : [Member] | Replies : 7
When I connect sqlsever 2008 r2 using windows authentication in SQLServer Management Studio it works fine

When I use the same username/password in an app to connect to the server I get the error message

string strcon = "Data Source=parthipc;integrated security =sspi;initial catalog =employee";
SqlConnection con = new SqlConnection(strcon);

SqlCommand com = new SqlCommand("insertrecord", con);
com.CommandType = CommandType.StoredProcedure;
SqlParameter p1 = new SqlParameter("username",TextBox1.Text);
SqlParameter p2 = new SqlParameter("email", TextBox2.Text);
SqlParameter p3 = new SqlParameter("password",TextBox3.Text);
com.Parameters.Add(p1);
com.Parameters.Add(p2);
com.Parameters.Add(p3);
con.Open();
com.ExecuteNonQuery();
con.Close();
Label1.Text= "registered successful.";

i get dis error "Cannot open database "employee" requested by the login. The login failed.
Login failed for user 'Parthi-PC\Parthi'".


Any help would be appreciated.




Responses

Posted by: Pandians on: 8/16/2012 [Member] [MVP] Silver | Points: 25

Up
0
Down
Could you able to connect with SQL Server using Management Studio ? (or) you facing any error ?

Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Parthibansk on: 8/16/2012 [Member] Starter | Points: 25

Up
0
Down
i can connect with SQL Server using Management Studio.. but using connection strings i cannot open database..
onemore thing cannot login sa using sqlserver authentication..




Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pandians on: 8/16/2012 [Member] [MVP] Silver | Points: 25

Up
0
Down
Check and let me know!

1. Right click on your Instance Name on Left pan of "Object Explorer"
2. Click Properties...
3. Click Security on left pan on Server Properties... window
4. Select "SQL Server and Windows Authentication mode" option... and Click OK

Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Arvsingh85 on: 8/16/2012 [Member] Starter | Points: 25

Up
0
Down
Go Through UDL
Open Notepad Save with .UDL Extension Test Your SQL Connection

Then Copy you database Connection link And Paste in to your project Editor.
thank You


arvind singh

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Parthibansk on: 8/16/2012 [Member] Starter | Points: 25

Up
0
Down

i get this error wen i test connection

Test connection failed becoz of error in initializing provider.
login failed for user sa..user not associated with trusted sql server connection

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Arvsingh85 on: 8/16/2012 [Member] Starter | Points: 25

Up
0
Down
Go Through .UDL
Open Notepad AND save Any name with .UDL Extension
Test Your SQL Connection Copy and paste into your project editor
Thank you


arvind singh

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: San.Pblr.Gct on: 8/16/2012 [Member] Starter | Points: 25

Up
0
Down
Check this link to reset sa user password.

http://blog.sqlauthority.com/2009/08/04/sql-server-forgot-the-password-of-username-sa/

I am not sure for the particular server, your windows authentication is configured. Please check it again in SSMS.

If you are able to then have you checked whether this user has read//write permission to Database employee?

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response