c# - A network-related or instance-specific error occurred while establishing a connection to SQL Server. Error Locating Server/Instance Specified) -
moving web project test enviroment web server made error occur whenever tehre's attempt open connection sql server.
we can insert , read data sql server management studio.
we're suspecting error created bad connection string or sql server using integrated security, haven't been able confirm that.
the connection string.
<connectionstrings> <add name="dsvushort" connectionstring="data source=localhost\sqlexpress;database=ns_survey; integrated security=true;multipleactiveresultsets=true;app=entityframework" /> </connectionstrings>
where used
sqlconnection connection = new sqlconnection(configurationmanager.connectionstrings["dsvushort"].tostring()); connection.open() // pops error
causes error connectionstring in webconfig
set connectionstring in webconfig.
name of connectionstrin in webconfig , code behind must same.
in web.config:
<configuration> <connectionstrings> <add name="dsvushort" connectionstring="data source=.\sqlexpress;attachdbfilename=|datadirectory|\database.mdf;integrated security=true;user instance=true" providername="system.data.sqlclient"/> </connectionstrings> <system.web> <compilation debug="true" targetframework="4.0"/> </system.web>
in code:
sqlconnection connection = new sqlconnection(configurationmanager.connectionstrings["dsvushort"].tostring()); connection.open();
Comments
Post a Comment