I’ve tried several different connection strings and always get the same error: Format of the initialization string does not conform to specification starting at index 22.
using System;
using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.Sql; using System.Data.SqlClient;
namespace WebApplication1 { public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) {
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection connection = new SqlConnection("Data Source=Brandon-PC\brandon;Initial Catalog=STATUS;integrated security=SSPI;persist security info=False;Trusted_Connection=Yes;");
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();
}
}
}
You need to quote backslash, either:
or
Plus, your code should be:
[Note: I’m assuming undescores are ok in the query text parameters; I never use them.]
[Also note: you do not need
integrated security=SSPIANDTrusted_Connection=Yes. They are synonyms; one is sufficient.]