search

Home  >  Q&A  >  body text

How to write SqlConnection in ASP.NET MVC?

 using (var connection = new SqlConnection(@"server=127.0.0.1;database=dbname;uid=sa;password=1234567890"))
            {
                 connection.Open();
                 try
                 {
                 ……

that is

System.ComponentModel.Win32Exception: 找不到网络路径。   

or

System.Data.SqlClient.SqlException: 在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。 (provider: SQL Network Interfaces, error: 50 - 发生了 Local Database Runtime 错误。无法创建自动实例。有关错误详细信息,请参阅 Windows 应用程序事件日志。

still have a question

Data Source=(LocalDB)\v11.0

If written like this, does it refer to the local database? What version is 11.0?

習慣沉默習慣沉默2872 days ago456

reply all(2)I'll reply

  • 大家讲道理

    大家讲道理2017-05-16 17:07:20

    Already solved. Change to

    server=.
    

    That’s it

    reply
    0
  • 阿神

    阿神2017-05-16 17:07:20

    Isn’t it popular to use ef in mvc now? Still using sql?

    reply
    0
  • Cancelreply