错误:40 - 无法打开与SQL Server的连接

时间:2015-05-22 09:22:11

标签: c# .net sql-server

您好我正在编写一个简单的控制台应用程序,使用批量复制将XML数据保存到数据库中,但目前我在连接数据库时遇到问题。

我收到SqlException错误:

  

发生与网络相关或特定于实例的错误   建立与SQL Server的连接。找不到服务器或   无法访问。验证实例名称是否正确   SQL Server配置为允许远程连接。 (提供者:命名   管道提供程序,错误:40 - 无法打开与SQL Server的连接)

我检查了确保我的SQL服务器正在运行并且配置正确的问题。下面是我的连接字符串。

string connectionString = @"Data Source=SYAZANA;Initial Catalog=WangSCM;integrated security=true;" ;

我正在努力弄清楚错误,我正在犯的错误是什么?

3 个答案:

答案 0 :(得分:2)

按照以下步骤操作:

*转到SQL Server配置管理器

* SQL Server网络配置:

* MSSQLSERVER协议

*在右侧窗格拆分页面中,您必须按如下方式禁用VIA

--->共享内存 - 启用

--->命名管道 - 启用

---> TCP / IP - 启用

---> VIA - 禁用

或尝试以下

转到开始 - >在搜索类型| id | name | points | |----|-------|--------| | 3 | Three | 12 | | 1 | One | 6 | | 2 | Two | 5 | 中。在那里,您可以找到系统中提供的服务。

寻找 - > SQL EXPRESS / Services.msc - >右键单击它 - >然后开始它。 如果它已经在开始。只需停止开始,或只是重新启动

答案 1 :(得分:2)

我发现以下技术很有用:

  1. 确保将数据库引擎配置为接受远程连接
  2. • Start > All Programs > SQL Server 2005 > Configuration Tools > SQL Server Surface Area Configuration
    • Click on Surface Area Configuration for Services and Connections
    • Select the instance that is having a problem > Database Engine > Remote Connections
    • Enable local and remote connections
    • Restart instance
    
    1. 检查SQL Server服务帐户
    2. • If you are not using a domain account as a service account (for example if you are using NETWORK SERVICE), you may want to switch this first before proceeding
      
      1. 如果您使用的是命名的SQL Server实例,请确保在ASP.NET Web应用程序的连接字符串中使用该实例名称
      2. • Usually the format needed to specify the database server is machinename\instancename
        • Check your connection string as well
        • If SQL Server is not configured on the default port (1433) then mention that port in the connection string
        
        1. 您可能需要在防火墙上为正在使用的SQL Server实例和端口创建例外
        2. • Start > Run > Firewall.cpl
          • Click on exceptions tab
          • Add the sqlservr.exe (typically located in C:\Program Files (x86)\Microsoft   SQL Server\MSSQL.x\MSSQL\Binn), and port (default is 1433)
          • Check your connection string as well
          
          1. 检查您的SQL服务器服务是否正常运行。

          2. 检查您是否已连接到SQL Server。请注意您用于连接的内容:计算机名称,域名或IP地址?检查连接时使用此选项。例如,如果您使用的是myserver

          3. • Start > Run > cmd
            • netstat -ano| findstr 1433
            • telnet myserver 1433
            • ping myserver
            
            1. 在SQL Server配置中启用TCP / IP
            2. • Go to All Programs >> Microsoft SQL Server 2008 >> Configuration Tools >> SQL Server Configuration Manager >> Select TCP/IP
              • Right Click on TCP/IP >> Click on Enable
              • You must restart SQL Server Services for all the changes to take effect.
              
              1. 配置SQL Server端口号。
              2. • Open "SQL Server Configuration Manager"
                • Click on "SQL Server Network Configuration" and Click on "Protocols for Name"
                • Right Click on "TCP/IP" (make sure it is Enabled) Click on Properties
                • Select "IP Addresses" Tab -and- Go to the last entry "IPAll"
                • Enter "TCP Port" 1433.
                

答案 2 :(得分:0)

我遇到了同样的问题,由于某种原因,我不得不添加标准的SQL端口(1433),然后一切都恢复了。在你的情况下:

driver.execute_script("document.getElementById('overridelink').click()")
driver.get "javascript:document.getElementById('overridelink').click()"
driver.get("javascript:document.getElementById('overridelink').click()");