I'm trying to insert data from a textbox into a SQL table. I created a SQL db on my local machine and the instance name is "Brandon-PC\brandon". The username is "Test" and the password is "test". The db is named "STATUS". I have added the user to the server as a sysadmin as well adding it in the STATUS db. For the "server = " argument I've tried Brandon-PC, Brandon-PC\brandon, and brandon I keep getting this error:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) I've posted the code below, and any help is appreciated.
RageQwit
Member
15 Points
11 Posts
Trouble with SQL connection string
Jan 25, 2012 08:49 PM|LINK
protected void Button1_Click(object sender, EventArgs e) { SqlConnection connection = new SqlConnection("server = brandon; uid = Test; pwd = test; database = STATUS;"); connection.Open(); string clientname = TextBox1.Text; string sqlquery = ("INSERT INTO [STATUS] (Client_Name) VALUES ('" + TextBox1.Text + "')"); SqlCommand command = new SqlCommand(sqlquery, connection); command.Parameters.AddWithValue("Client_Name", clientname); command.ExecuteNonQuery(); }