简体   繁体   中英

Console application can't connect to sql server instance from server, but can from local machine

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.

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" />

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

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)

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..

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?

Many thanks

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

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

telnet <ip>, 1433

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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