简体   繁体   English

无法连接到SQL Server 2008 R2

[英]Unable connect to SQL Server 2008 R2

I have a C# project with SQL Server 2008 R2 and the project runs with no problem on my local machine and when I publish it to the server Win2008 R2. 我有一个带有SQL Server 2008 R2的C#项目,并且该项目在本地计算机上运行以及将其发布到服务器Win2008 R2时都没有问题。 But the project doesn't work and can't connect to the server with no error. 但是该项目无法正常运行,并且不能正确连接到服务器。 All the database setting check and I enabled TCP/IP setting and etc. But still not worked. 所有数据库设置检查,我启用了TCP / IP设置等。但是仍然无法正常工作。 I think the problem is with connection string that is below. 我认为问题出在下面的连接字符串上。 When pages going to connect to the database, nothing happened in browser and browser stick in loading mode (waiting for respond). 当页面要连接到数据库时,浏览器中没有任何反应,并且浏览器停留在加载模式下(等待响应)。

Connection string on my computer 我计算机上的连接字符串

Data Source =(Local);Initial Catalog=Bulk;Integrated Security=True;Timeout=0;Max Pool Size=5000;

Connection string on Windows server Windows服务器上的连接字符串

Data Source=My Ip Windows Server,1433;Network Library=DBMSSOCN;Initial Catalog=Bulk;User ID=administrator;Password=My Windows Login Pass;Timeout=0;Max Pool Size=5000;

I got this error: 我收到此错误:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. 建立与SQL Server的连接时发生与网络相关或特定于实例的错误。 The server was not found or was not accessible. 服务器未找到或无法访问。 Verify that the instance name is correct and that SQL Server is configured to allow remote connections. 验证实例名称正确,并且已将SQL Server配置为允许远程连接。 (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified (提供者:SQL网络接口,错误:26-指定服务器/实例时出错)

In your connection string of Server you have: 在服务器的连接字符串中,您具有:

  1. Data Source=My Ip Windows Server,1433;Network Library=DBMSSOCN;
    To connect via IP Address and Port of 1433 and over TCP/IP protocol 通过IP地址和1433端口以及TCP / IP协议进行连接
  2. Initial Catalog=Bulk;
    Bulk is your database name Bulk是您的数据库名称
  3. User ID=administrator;Password=My Windows Login Pass;
    Authenticate via SQL Server connection by administrator login user and its password. 通过administrator登录用户及其密码通过SQL Server连接进行身份验证。

I think your problem is in third part that you want to connect to SQL Server by your Windows user name; 我认为您的问题出在第三部分,您想通过Windows用户名连接到SQL Server。 You can see valid logins of your SQL Server in Security branch of your registered server in SQL Server Management Studio that will shows your Windows user name like Domain Name\\User Name so you need to change User Id to that . 您可以在SQL Server Management Studio中已注册服务器的“安全性”分支中看到SQL Server的有效登录名,该登录名将显示Windows用户名,例如“ Domain Name\\User Name因此您需要将“ User Id更改

Configure the Windows Firewall to Allow SQL Server Access. 配置Windows防火墙以允许SQL Server访问。 open port 1433 in windows firewall. 在Windows防火墙中打开端口1433。 see this link . 看到这个链接 Or this . 还是这个

Please Try to connect in your local Sqlserver With Live Login Detail, If you are Success Then There should be Permission Need to set From the Live Hosting Server 请尝试使用实时登录详细信息连接本地Sqlserver,如果成功,则需要从Live Hosting Server设置权限

if is it possible then please add the More specification. 如果可能的话,请添加更多规格。

You should log the errors that occur, eg in Application_Error if it's actually an ASP.Net project. 您应该记录发生的错误,例如,如果Application_Error实际上是一个ASP.Net项目,则记录在其中。 Using the log you should get errormessages that hint you or enable you to give more details so nobody has to guess what your actual issue is. 使用该日志,您应该会得到提示或使您能够提供更多详细信息的错误消息,从而使您不必猜测实际问题是什么。

Regarding your issue: Did you give your Windows account the necessary READ/WRITE access on SQL Server? 关于您的问题:您是否向Windows帐户授予了对SQL Server的必要读/写访问权限? On MS SQL Server the account needs access to: 1. Be added to the general Security/Logins for an actual match of Windows account to Login. 在MS SQL Server上,该帐户需要访问:1.被添加到常规“安全性/登录”中,以使Windows帐户与“登录”实际匹配。 2. Be added to the specific database Security/Users tab with the necessary database role membership. 2.使用必要的数据库角色成员身份添加到特定的数据库“安全性/用户”选项卡。

In addition to specifiying your Windows account + password in the connectionstring: maybe it's better to run the application pool using a service-account and use 除了在连接字符串中指定Windows帐户+密码外,也许最好使用服务帐户来运行应用程序池并使用

Integrated Security=True

and remove 并删除

User ID=administrator;Password=My Windows Login Pass;

I have changed my connection string to this and problem solved. 我将连接字符串更改为此并解决了问题。

public static string ConnectionString = "Data Source=My Ip,1433;Initial Catalog=My DataBase;UID=sa;Pwd=My Pass;Timeout=0;Max Pool Size=5000;";

In sql server management studio Click "Security" => "Logins" => "sa" right-click and click properties in the left side click "Status" and in the right side,Choose enable in login 在sql Server Management Studio中,右键单击“安全性” =>“登录” =>“ sa”,然后单击左侧的属性,然后单击“状态”,然后在右侧选择启用登录

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM