c# - ASP.Net form throwing SQL exception -
when trying save , store data in local sql database, sql exception thrown,
"a network-related or instance-specific error occurred while establishing connection sql server. server not found or not accessible. verify instance name correct , sql server configured allow remote connections. (provider: named pipes provider, error: 40 - not open connection sql server)"
initially thought wrong way had made new data connection. after making new table 3 times, problem persisted. tried re-install sql modules of visual studio, did not yield +ve result.
no data can read from/stored table. please help.
public partial class signup : system.web.ui.page { sqlconnection conn = new sqlconnection("data source=(localdb)\v11.0;initial catalog=kidzquiz;integrated security=true"); sqlcommand cmd; sqldataadapter da; dataset ds; protected void signupclick(object s, eventargs e) { //if (checkduplicate() != 0) //signup_error.text = "user exists"; //else if (checkempty() != 1) // signup_error.text = "one or more fields missing"; //else //{ string sqlcmd = "insert user (name, email, school, city, standard, section) values (@n, @em, @sc, @city, @st, @sec)"; cmd = new sqlcommand(sqlcmd, conn); cmd.parameters.addwithvalue("@n", name.text); cmd.parameters.addwithvalue("@em", email_signup.text); cmd.parameters.addwithvalue("@sc", school.text); cmd.parameters.addwithvalue("@city", city.text); cmd.parameters.addwithvalue("@st", standard.selecteditem.tostring()); cmd.parameters.addwithvalue("@sec", section.selecteditem.tostring()); conn.open(); cmd.executenonquery(); conn.close(); //} }
}
in localdb local databases have give path database file also.
data source=(localdb)\v11.0;attachdbfilename=|datadirectory|\db.mdf;integrated security=true
|datadirectory| represents app_data folder of application
Comments
Post a Comment