Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2003
    Posts
    44

    Unanswered: 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?

  2. #2
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    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

  3. #3
    Join Date
    Dec 2003
    Posts
    44
    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?

  4. #4
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    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??

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •