asp.net - SqlException after moving connection string to web.config -
i have change data source name of server [server name]\sqlexpress after moving connection string page_load web.config. otherwise sqlexception @ con.open(). app works fine both ways wondering why need change datasource name after moving connection string.
<connectionstrings> <add name="cs" connectionstring="data source=[server name]\sqlexpress; initial catalog = sampledb; integrated security = true" providername="system.data.sqlclient"/> </connectionstrings> (string cs = "data source=.\\sqlexpress; initial catalog = sampledb; integrated security= true";)-moved web.config string cs = configurationmanager.connectionstrings["cs"].connectionstring; //pass connection string sqlconnection() constructor sqlconnection con = new sqlconnection(cs); //tell sqlcommand query execute , connection sqlcommand cmd = new sqlcommand("select * electronics", con); //open connection con.open(); //execute command gridview1.datasource = cmd.executereader(); gridview1.databind(); //close connection con.close();
Comments
Post a Comment