I am trying to create registiration. Here is web.config
<configuration>
<connectionStrings>
<clear/>
<add name="connect" connectionString="Data Source=.\SQLEXPRESS; AttachDbFilename=|DataDirectory|web.mdf; Security=True; uid=Rahman\Rahman; pwd=12345;"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>
and here I use sql query to write data into table called Users
protected void btnReg_Click(object sender, EventArgs e) {
SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["connect"].ConnectionString);
string q = "Insert into Users (Username, Password) Values(@username, @password)";
SqlCommand cmd = new SqlCommand(q, cnn);
cnn.Open();
try {
cmd.Parameters.AddWithValue("@username", txtUsername.Text);
cmd.Parameters.AddWithValue("@password", txtPass.Text);
cmd.ExecuteNonQuery();
cnn.Close();
textReg.Text = "Pozitive";
}
catch {
textReg.Text = "Negative";
}
}
But unfortunately I got error
"An exception of type 'System.ArgumentException' occurred in System.Data.dll but was not handled in user code"
Error points this line,
SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["connect"].ConnectionString);