Click to See Complete Forum and Search --> : DBconnection.Open "DSN=infish.dsn;uid=admin;pwd=;database=infish" doesn't work


Jan Hansen
January 28th, 2000, 06:49 AM
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

Lothar Haensler
January 28th, 2000, 06:53 AM
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?

Jan Hansen
January 28th, 2000, 09:43 AM
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

Gary Grant
January 28th, 2000, 12:12 PM
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"

czimmerman
January 28th, 2000, 05:10 PM
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