控制台应用程序无法从服务器连接到SQL Server实例,但可以从本地计算机连接 [英] Console application can't connect to sql server instance from server, but can from local machine

查看:123
本文介绍了控制台应用程序无法从服务器连接到SQL Server实例,但可以从本地计算机连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些运行在专用服务器上的asp.net Web应用程序。对于其中一个网站,我正在执行一项维护任务,将所有用户上传的图像升级为新的命名约定。

I have a few asp.net web applications running on a dedicated server.. For one of the websites, I am doing a maintenance task of upgrading all user uploaded images to new naming convention.

我写了一个简单的小型控制台应用程序来完成这项工作。像这样将连接字符串放入我的app.config中:

I wrote a small, simple console application to do that job. I put the connection string in my app.config like so:

<add key="CS" value="Data Source=1.1.1.1;Initial Catalog=MyDatabase;User ID=usr; Password=pwd" />

当然,这里的详细信息是虚拟的,它们实际上不是 MyDatabase 等...但是我确实使用IP地址连接到sql服务器

Of course, the details here are dummy they are not actually MyDatabase etc... but I do connect to the sql server using an IP address

我所有的Web应用程序都具有相同的格式,其 web.config 文件中的详细信息相同,只是数据库名称例外。一切也都正常。

All my web applications have same format, same details in their web.config files, with the exception of just the database name. Everything works fine too.

我可以从本地开发机器上运行控制台应用程序,并与生产数据库一起运行,并且可以很好地连接。 (成功地在测试数据库上运行了一个测试查询)

I can run the console application from my local dev machine, with the production database, and it connects fine, no problem. (ran a test query on a test DB successfully)

现在,我需要访问硬盘以重命名文件等,因此我想运行此控制台应用程序我将应用程序FTP传输到我的服务器上,然后尝试在该服务器上运行它。错误提示:

Now, I need to access the hard disk to rename files etc... so I want to run this console application on the server.. I FTP the app to my server and try to run it there.. it errors out saying:

A network-related or instance-specific error occurred while establishing
a connection to 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. (provider: SQL Network Interfaces,
error : 26 - Error Locating Server/Instance Specified)

就像我之前提到的,我的开发机上的相同连接运行良好,只有当我尝试在服务器上运行控制台应用程序时才会发生这种情况。

Like I mentioned earlier, same connection is running fine from my dev machine, this only happens when I try to run the console application in the server..

尝试搜索,但在任何地方都找不到类似的情况。因为所有使用相同值的Web应用程序都可以正常工作..我需要告诉应用程序使用某些东西吗?

I've tried searching but couldn't find a similar case anywhere.. esp. as all my web applications that use the same value works fine.. do I need to tell the application to use something?

非常感谢

推荐答案

Web服务器和数据库服务器位于

Are the web server and DB server on the same machine?

无论如何,在Web服务器上打开命令提示符并执行以下操作:

Regardless, on the web server open a command prompt and do the following:

telnet <ip>, 1433

这假设您正在运行SQL服务器在标准端口上,如果没有,则进行相应的更改。

This assumes your running your SQL Server on the standard port, change accordingly if not.

查看是否可以通过telnet连接到DB Server,有助于确定是否存在防火墙/基本的连接问题。

See if you can connect to the DB Server via telnet, helps figure out if there are firewall/basic connection issues.

这篇关于控制台应用程序无法从服务器连接到SQL Server实例,但可以从本地计算机连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆