Click to See Complete Forum and Search --> : ODBC Connection


sunitha
November 25th, 1999, 07:18 AM
I need to know where is the error in following code for MS ACCESS connection through ODBC. Can I have the corrected code ?



private Sub Form_Load()
Dim PrivDb as Database
set PrivDb = OpenDatabase("", false, false, "ODBC;DSN=Hospital;UID=xxx;Pwd=xxx;")
End Sub




ODBC setting :
ODBC Driver = Microsoft Access Driver (*.mdb)
DSN = Hospital
Database = C:\Hospital
UID = xxx
PWD = xxx

Note : The above code is working if i change the driver to Sql Server

Thanks.

Vlado B
November 25th, 1999, 05:26 PM
Try to Change UID= to User ID= & PWD= to Pasword=

Ranjit Goray
November 26th, 1999, 07:08 AM
There is a error in the openrecordset statement... iF you are using ADO then you just have to pass the database name and the dsn name
e.g.

dim objectname as new Connection
dim strconnect as string

strconnect = "Database=Hospital;dsn=dsnHospital"
objectname.open (strconnect)

santulan
November 27th, 1999, 01:54 AM
sunitha,
I used following with RDO.

Global Cn as rdoConnection
public Sub Main()
Dim Cnct as string
Cnct$ = "DSN=MS ACCESS;UID=santulan;PWD=beluz1;DATABASE=EOC.mdb;"
set Cn = rdoEnvironments(0).OpenConnection("", rdDriverNoPrompt, false, Cnct$)




This works :-)>.
In your project reference add RDO object before trying it.



Santulan