CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2000
    Location
    DK
    Posts
    5

    DBconnection.Open "DSN=infish.dsn;uid=admin;pwd=;database=infish" doesn't work

    Hi everybody

    I'm trying to create an .exe file that will be accessed throught the ineternet (http://whatever/test.exe) - and this .exe file must have access to my database. I have created a file-DSN (works fine in ASP), and I want to connect to the database using that same file-DSN. When I do this:

    DBconnection.Open "DSN=infish.dsn;uid=admin;pwd=;database=infish"



    it doesn't work...
    - I get an error number 19:

    Object variable or With block variable not set. Does anyone have a clue on what I'm doing wrong ? The database is not password protected, but I get the same error if I use the following strings:
    DBconnection.Open "DSN=infish.dsn", "", ""


    or
    DBconnection.Open "DSN=infish.dsn"



    Do I have to specify the DSN more specific ? or is it something else ?

    Any help will be greatly appreciated

    best regards
    Jan Hansen


  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: DBconnection.Open "DSN=infish.dsn;uid=admin;pwd=;database=infish" doesn't work

    IMHO the error message indicates that your DBConnection is not instantiated yet.
    How do you do that?
    via
    Dim DBC... as new ADODB.Connection
    or
    Dim DBC... as ADODB.Connection
    set dbc... = new adodb.connection?

    If I understand you correctly your EXE will be loaded to the client and executed on the client's machine. In that case the file dsn must be installed on the user's machine. How do you do that?



  3. #3
    Join Date
    Jan 2000
    Location
    DK
    Posts
    5

    Re: DBconnection.Open "DSN=infish.dsn;uid=admin;pwd=;database=infish" doesn't work

    My man....allways there...

    Thanks for the reply, I have (now) tryed both versions, and it helps - sort of.

    Now I get the message (translated from danish)
    [Microsoft][ODBC Driver Manager] The datasourcename was not found, and no standarddriver has been given

    - bad translation, but it seems like it doesnt know the DSN and doesnt know that this is an access database. The DSN exists - I use it in ASP, but something must be wrong anyway.

    The executeable is not executed on the clients machine - but on the server (NT 4.0 SP5), and therefore the DNS doesnt have to reside on the client machine. However - even if I try to call the executeable through a browser on the server-machine (that indeed do know the DSN) it doesn't work.

    Here's all the code - it should work (most of it is from MSDN):

    public Sub printTable(tableName as string)

    ' Dim DBconnection as new ADODB.Connection
    Dim DBconnection as ADODB.Connection
    Dim cmd as new ADODB.Command
    Dim RS as new ADODB.Recordset

    Send "nu er vi i printtable" 'debug

    set DBconnection = new ADODB.Connection

    'dsnstring = "DSN=c:\Program Files\Common Files\Odbc\Data Sources\infish.dsn"
    'dsnstring = "DSN=infish"
    'DBconnection.Open dsnstring, "", "", "-1"
    ' DBconnection.Open "DSN=infish.dsn", "", ""

    DBconnection.Open "DSN=infish.dsn;uid=admin;pwd=;database=infish"

    cmd.CommandText = "SELECT * FROM Brugere"

    RS.Open cmd, DBconnection, adOpenDymanic, adLockBatchOptimistic

    RS.Sort = "Efternavn ASCENDING"

    RS.MoveFirst
    Do While Not RS.EOF
    Send RS!Fornavn & "
    " & RS!Efternavn
    RS.MoveNext
    Loop

    RS.Close
    DBconnection.Close


    End Sub







  4. #4
    Join Date
    Apr 1999
    Location
    Michigan, USA
    Posts
    115

    Re: DBconnection.Open "DSN=infish.dsn;uid=admin;pwd=;database=infish" doesn't work

    I do not know if a file dsn can be used with ADO but with ODBC you would code something like

    DBconnection.Open "FileDSN=infish.dsn"






  5. #5

    Re: DBconnection.Open "DSN=infish.dsn;uid=admin;pwd=;database=infish" doesn't work

    Did you initialize the DBConnection variable either by saying:

    VB:

    Dim DBConnection as new ADODB.Connection

    or

    Set DBConnection = new ADODB.Connection

    ASP

    Set DBConnection = Server.CreateObject("ADODB.Connection")

    Charlie Zimmerman
    http://www.freevbcode.com



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

Featured