c# - After registering to my website instead of inserting the data to the sql server, an error message appears -


in asp website have register form sends data database. when user enters data, after submitting, error appeared says:

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: sql network interfaces, error: 26 - error locating server/instance specified)

this code: signup.aspx.cs-

protected void submit_click(object sender, eventargs e) {     string name = request.form["name"];     string email = request.form["email"];     string password = request.form["password"];     string filename = "database.mdf";     string sql = "insert userinfo values('" + name + "','" + email + "','" + password + "')";     myadohelper.doquery(filename,sql); } 

myadohelper.doquery-

public static void doquery(string filename, string sql) {      sqlconnection conn = connecttodb(filename);     conn.open();     sqlcommand com = new sqlcommand(sql, conn);     com.executenonquery();     com.dispose();     conn.close();  } 

myadohelper.connecttodb-

 public static sqlconnection connecttodb(string filename) {     string path = httpcontext.current.server.mappath("app_data/");     path += filename;     //string path = httpcontext.current.server.mappath("app_data/" + filename);     string connstring = @"data source=.\sqlexpress;attachdbfilename=" +                          path +                          ";integrated security=true;user instance=true";     sqlconnection conn = new sqlconnection(connstring);     return conn;  } 

my database name database.mdf , under app_data folder

could tell me problem? thx !

a network-related or instance-specific error occurred while establishing connection sql server. server not found or not accessible.

above error message suggest instance name ".\sqlexpress" wrong. please first confirm instance name.

by word "registering" guess means "hosted in webserver". in case connection string won't work way. can find connection string sql server in hosting providers control panel. or can ask them connection string , mention them using sql db local file attached application. example can provide them current connection string.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -