Monday, March 12, 2012

localhost question

I have always connected to my MS SQL DB's through a remote connection, like this:

<%
Dim oConn, oRS, sSQL
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open "Driver={SQL Server};" & _
"Database=mydb;" & _
"Server=myservername;" & _
"UID=mylogin;" & _
"PWD=mypwd"
%>

Is there a way to connect to an MS SQL DB locally with VBScript... I have seen code blocks use the keywork localhost... does that have something to do with it?localhost will point to the local machine...

if you look in your hosts file you will find localhost is mapped to 127.0.0.1 which is the loopback address for the ethernet adapater...

So yeah,.. you can use the machine name specificly, the ip number for the local machine, localhost, or 127.0.0.1 as your myservername value|||Originally posted by rokslide
localhost will point to the local machine...

if you look in your hosts file you will find localhost is mapped to 127.0.0.1 which is the loopback address for the ethernet adapater...

So yeah,.. you can use the machine name specificly, the ip number for the local machine, localhost, or 127.0.0.1 as your myservername value

Ahhhh I see... but that gives me a problem... localhost only works if you are running SQL Server on your own machine. I wanted to connect to a server that I don't run, then, even if the website is located on the same network as the SQL server, I would have to connect to it remotely?|||if the website is on the same box as the database then when the vbscript to connect to the database is executed it will execute in the context of the server it resides on... so localhost would work...

if you then took the code and tried to run it on your machine it would look on your machine for the database which would fail.

does that make sense??

No comments:

Post a Comment