Click here to Skip to main content
16,016,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void button1_Click(object sender, EventArgs e)
        {
        
            SqlConnection con = new SqlConnection();
            con.ConnectionString = "database=test;server=.\\sqlexpress;integrated security=true; user instance=true; user=user;password=passwd";
            con.Open();
            SqlCommand cmd=new SqlCommand();
            cmd.Connection = con;
            cmd.CommandType=CommandType.Text;
            cmd.CommandText="insert into tbemp(Name,Address,Salary) values(@nm,@ad,@sal)";
            cmd.Parameters.Add("@nm",SqlDbType.VarChar,50).Value=textBox1.Text;
            cmd.Parameters.Add("@ad",SqlDbType.VarChar,50).Value=textBox2.Text;
            cmd.Parameters.Add("@sal",SqlDbType.VarChar,50).Value=textBox3.Text;
            cmd.ExecuteNonQuery();
        }


Cannot open database "test" requested by the login. The login failed.
Login failed for user 'user-PC\Administrator'.

what can be the error,please help.

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 21-Jun-12 8:03am
v2

1 solution

Take "user instance=true" out - it causes SQL server to try to log you in to Windows on the SQl server as the user "user" which is probably what is failing.
http://msdn.microsoft.com/en-us/library/bb264564(v=sql.90).aspx[^], about 1/3 of the way down.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900