Reputation: 139
Trying to access a SQL Server 2014 database with Visual Studio 2017; on each run, it shows this error
System.ArgumentException: Format of the initialization string does not conform to specification starting at index 124
Read some questions already on stack overflow but they are of other context. Like asp.net or azure database etc
<configuration>
<connectionStrings>
<add name="EMPLOYES"
connectionString="Data Source=DESKTOP-0ROOGH3\SQLEXPRESS;Initial Catalog=EMPLOYES;Integrated Security = true;System.Dat.SqlClient"/>
</connectionStrings>
</configuration>
Code:
private void button2_Click(object sender, EventArgs e)
{
String conString = ConfigurationManager.ConnectionStrings["EMPLOYES"].ConnectionString;
// here I get the exception
SqlConnection conn = new SqlConnection(conString);
SqlCommand cmd = new SqlCommand("AddNewEmployee", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@EmployeeID", SqlDbType.NVarChar, 8).Value = EmpIDTextBox.Text;
cmd.Parameters.Add("@FirstName", SqlDbType.NVarChar, 50).Value = FirstNameTextBox.Text;
cmd.Parameters.Add("@LastNmae", SqlDbType.NVarChar, 50).Value = LastNameTextBox.Text;
cmd.Parameters.Add("@Email", SqlDbType.NVarChar, 50).Value = EmailTextBox.Text;
cmd.Parameters.Add("@Telephone", SqlDbType.NVarChar, 50).Value = TelephoneTextBox.Text;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("Employee is added successfully!");
}
I expected to insert records but it generates some exception
Upvotes: 3
Views: 515
Reputation: 81473
Your connection string looks completely garbled, try something like
<configuration>
<connectionStrings>
<add name="EMPLOYES"
connectionString="Data Source=DESKTOP-0ROOGH3\SQLEXPRESS;Initial Catalog=EMPLOYES;Integrated Security = true;"
providerName="System.Data.SqlClient" />
</connectionStrings>
</connectionStrings>
Additional Resources
Upvotes: 2