Results 1 to 11 of 11

Thread: DSN vs. Direct Connection

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    40

    Exclamation

    i have a question for all the DB gurus out there. I am trying to connect to a DB on my ISP's server. I recently created a DSN for a program that works fine on my personal web server. To avoid my ISP creating a virtual ditrectory and so on.... someone suggested that I can create a connection directly and skip all the DSN stuff. I need help on the code to do so. Heres what I have:
    ---------------------------
    Dim SqlJunk


    Set dbGlobalWeb = Server.CreateObject("ADODB.Connection")
    dbGlobalWeb.Open("Employees")

    SqlJunk = "SELECT * FROM Employees"

    --------------------------------

    I appreciate all help, thanks!!!!!!!!!!!!!!!

  2. #2
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    You will need to know the DB server's name and supply the provider:

    cn.ConnectionString = "Provider=SQLOLEDB;Server=Servername;Database=DatabaseName;UID=UserId;Pwd=Password;


    Fill in the right-side values above with yours (assuming your using SQL Server you'll need to change the provider if not)

    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    40

    ERRORS!

    Now I have:
    -----------------

    Dim SqlJunk

    Set con = CreateObject("ADODB.Connection")
    con.ConnectionString="PROVIDER='MICROSOFT.JET.OLEDB.4.0';Server=servername;Database=employees.mdb;UI D=id;Pwd=password;"
    con.Open
    --------------------------------

    I am getting:

    Microsoft JET Database Engine error '80004005'

    Could not find installable ISAM.

    line 14

    -------------------

    I think it's when I open it???



  4. #4

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    40

    Question ideas...

    any ideas??? Or am I totally off on my code?????
    Help anyone!!!!!!!!!!!

  5. #5
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    If you use Jet OLEDB provider, then you need to assign Data Source to a physical path to the database:
    Code:
    Dim cn
    
    Set cn = Server.CreateObject("ADODB.Connection") 
    cn.ConnectionString="PROVIDER=MICROSOFT.JET.OLEDB.4.0;Data Source=C:\MyDatabase.mdb" 
    cn.Open
    Notice C:\MyDatabase.mdb - it should be a physical path to the database on the server.

  6. #6
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    Probably a better idea would be to get the server path rather than hard code the path but Serge is right, for an access database you have to specify where it physically is.
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  7. #7
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Or better yet, create a DSN for an Access database on the server and then use DSN instead.

  8. #8
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    That would be ideal but it doesn't sound like he has direct access to the server. He is being hosted through an ISP. I doubt if they would be willing to set up a DSN on their server for him so a direct connection will be necessary.
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  9. #9
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    He can create a file DSN that he can upload (since he probably has permissions to upload his files like ASP and HTML) to the server and use it almost the same as User/System DSN.

    Code:
    <%
        Dim cn
    
        Set cn = Server.CreateObject("ADODB.Connection")
        cn.Open "FileDSN=MyDSN", UserName, Password
    %>

  10. #10
    Addicted Member
    Join Date
    May 2000
    Location
    Grand Rapids, MI
    Posts
    231

    Just so you know

    I just wana make sure you know this, a DSN is just a setting in the ODBC Registry, it allows you to use just a DSN name so that you dont have type out all that same information, but in both cases, you have the exact same information, just with a DSN , it's Pre-Saved in ODBC, and you can use it through out your program.

    also if you are using a Access DB, your friend if viewing your ASP on a browser, will NEVER have direct access, but instead whatever you do with the Access will show out to the screen, you may use RDO (Remote Data Object) to truely have direct access through a browser, or you can setup a SQL Server, and have him log into a sql server using his own login tools, but using ADO, the user viewing the page never has direct access because it's a serverside process.
    -Karl Blessing aka kb244{fastHACK}
    [email protected]

  11. #11
    New Member
    Join Date
    Sep 2000
    Location
    Milwaukee, WI
    Posts
    1

    Cool DSN-Less Connection is what you want

    Here is an optimized vbscript of what you want to do, this should help you out...
    Code:
    Set DB = Server.CreateObject("ADODB.Connection")
    DB.open "DBQ=" & SERVER.MapPath("your.mdb") & ";DRIVER={Microsoft Access Driver (*.mdb)};"
    
    Set cmdTemp = Server.CreateObject("ADODB.Command")
    Set rs = Server.CreateObject("ADODB.Recordset")
    cmDTemp.CommandText = "SELECT * FROM YourTable"
    cmdTemp.CommandType = 1
    Set cmdTemp.ActiveConnection = DB
    rs.Open cmdTemp, , 3, 3
    This will allow you to not have to worry about where the database is located physically on the server, and better yet, if it is moved, your data won't crap out on you...this is also available for SQL7 databases as well...

    Code:
    strconn = "Driver={SQL Server};Description=sqldemo;SERVER=127.0.0.1;UID=LoginID;PWD=Password;DATABASE=Database_Name
    set conn = server.createobject("adodb.connection")
    conn.open strconn
    This should make you dangerous enough to continue on with your project...Good luck
    My Humble Opinion is the only one that counts...just kidding.

Posting Permissions

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



Click Here to Expand Forum to Full Width