A network-related or instance-specific error occurred while establishing a connection to SQL Server. Error Locating Server/Instance Specified)

前端 未结 1 1065
陌清茗
陌清茗 2020-12-21 23:35

Moving a web project from test enviroment to the web server made this error occur whenever tehre\'s an attempt to open a connection to the sql server.

We can insert

相关标签:
1条回答
  • 2020-12-21 23:53

    causes this error is connectionString in webConfig
    Set connectionString in webConfig.
    name of connectionStrin in webConfig and code behind must be 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();
    

    enter image description here

    0 讨论(0)
提交回复
热议问题