We help IT Professionals succeed at work.

Need to connect to a SQL server database hosted on another server

Medium Priority
Last Modified: 2010-03-19

I need to produce a web site in ASP hosted on my own Windows 2003 server. The problem is I need to have read access to a SQL server database that is hosted on another external web server. I need to know how to set up the connection string and what the IT people need to do to enable my script to access the database.

Watch Question

From my machine at home using code like this I can access an MS SQL Server across the world:
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open(driver={SQL Server}; server=,0000; database=databaseName; User ID=sa; password='yourPassword')
'   do ya lookups etc here
Set conn = Nothing

all you need is the IP and sometimes port (the bit after the comma), your database name, user id and password.
whoops, forget the quote marks around the connection, should look like the below, just make it into a tests.asp page anywhere offline and run it with your servers IP and what I said above
Set conn=Server.CreateObject("ADODB.Connection")
conn.Open("driver={SQL Server}; server=,0000; database=databaseName; User ID=sa; password='yourPassword'")
'   do lookups etc here
Set conn = Nothing

Open in new window


Great thanks for this. I will test this out then get back to you.

Before I do so I noticed the following:

What is the ",0000" at the end for? Is this some kind of bit mask?

that's the port as is just something I'm using with a remote server, it may simply be an IP address for you. Perhaps in your hosting control panel it offers you their "path"? If not you probably have to ask them for it because of course it will be different from your home to being on their local server! I hope that makes sense.

p.s. I *think* the last four digits are the port number, I can't think what else they would be.
The ,#### in the server is the port number.  In the event that you are attaching to an instance, your server path may be {server}\{InstanceName}.  But if you specify a port number (such as the default of 1433) it will ALWAYS go to that port number and not necessarily the named instance specified.  To avoid this, do not use the port number unless told to.  

Explore More ContentExplore courses, solutions, and other research materials related to this topic.