从C#应用程序访问远程sql服务器

问题描述:

大家好.

我有一个C#应用程序(VS社区2015),用于访问本地计算机上的Sql Server 2014 Express实例.该过程在我的本地计算机上可以正常运行,但是当我尝试从远程计算机上运行该应用程序时失败.远程计算机已开启 我的家庭网络,就像服务器计算机一样,并且该网络未设置为域.我为SQL添加了一个专门针对该应用程序的登录名,并在连接字符串中使用了该登录名.我得到的错误是一个告诉我它找不到sql服务器的错误. 服务器设置为接受sql登录,并使用默认端口启用了tcip/ip和命名管道.我什至尝试将我创建的登录名添加到sql admins组中.这是我正在使用的连接字符串:

I have a C# application (VS community 2015) that accesses a Sql Server 2014 Express instance on my local machine. The process works fine on my local machine but fails when I try to run the application from a remote computer. The remote computer is on my home network, just as the server machine is, and the network is not set up as a domain. I added a login specifically for the application to sql and use that in the connection string. The error I get is one telling me that it cannot find the sql server. The server is set to accept sql logins and both tcip/ip and named pipes are enabled, using the default ports. I even tried adding the login I created to the sql admins group. Here is the connection string I'm using:

Server = myComputerName \\ SQLEXPRESS; Database = myDatabase; User Id = myUser;密码= myPassword

Server=myComputerName\\SQLEXPRESS;Database=myDatabase;User Id=myUser; Password=myPassword

显然,为了保护无辜者,他们的名字已经更改:

Obviously the names have been changed to protect the innocent :)

sql服务和sqlbrowser服务都在运行. sqlAgent服务不是,但有人告诉我这是sql Express的局限性.

The sql service and the sqlbrowser service are both running. The sqlAgent service is not, but I'm told that is a limitation of sql Express. 

我会很感激您的任何见解.谢谢!

I would appreciate any insights you folks might have. Thanks!

迈克尔

您好,哈尔达克,

Hi Khaldac,

请查看以下文章,如何为远程SQL Server设置连接字符串.希望对您有帮助.

Please look into the below article how to setup connection string for remote SQL Server. Hope this helps you.

用于C#的远程SQL服务器的正确连接字符串

生成SQL Server连接字符串