by Chaudhary Pradeep Kr Roy (6 Submissions)
Category: Databases/Data Access/DAO/ADO
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sat 29th November 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Using this code u can make DSN less Connection
'\ Opening DSN LEss Connection In Ms Access, Sql Server and Oracle
Provider=MSDASQL.1;Persist Security Info=False;User ID=<<UID>>;Data Source=<<DATS SOURCE NAME>>
Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Data Source=TestSvr
DSN=<DSN NAME>>;UID=<<UID>;PWD=<<PWD>>;SERVER=<<SERVER NAME>>;
''Establishing Connection Using ODBC provider
Dim con As New ADODB.Connection
con.Open "Driver={Microsoft Access Driver (*.mdb)}; dbq=Biblio.mdb; DefaultDir=C:\Program Files\Microsoft Visual Studio\VB98; uid=admin; pwd="
Print "Access connection state=" & con.State
con.Close
con.Open "Driver={Oracle ODBC Driver}; dbq=beq-local.world ;uid=scott; pwd=tiger"
Print "Oracle connection state=" & con.State
con.Close
'Note: This connection is tested on both Personal Oracle 8 and Oracle 8i. Only change you make while using it with oracle8i client is to use Net 8 service name as value of dbq parameter.
con.Open "Driver={SQL Server}; Server=Server1; Database=pubs; uid=sa; pwd="
Print "SQL Server connection state=" & con.State
con.Close
'Establishing Connection Using Oledb provider
con.Open "Provider=Microsoft.Jet.Oledb.4.0; Data Source=DATA BASE NAME WITH ABSOLUTE PATH; User Id=admin; Password="
'Note: connectionstring in above example makes use of provider for Access 2000 database. For earlier version of database use Provider=Microsoft.Jet.Oledb.3.51
con.Open "Provider=MSDAORA.1;Password=tiger;User ID=scott;Data Source=beq-local.world"
con.Open "Provider=SQLOLEDB.1;User ID=sa;password=;Data Source=(local); Initial Catalog=Northwind"
==================
'ODBC DSN Connection
public Cn as ADODB.Connection
public Rc as ADODB.Recordset
public Sql as String
private sub form_load()'Enter This Part Form Load Event
set Cn = new ADODB.Connection
set Rc = new ADODB.Recordset
cn.open "MYODBC","UserName","Password"
while not Rc.Eof
list1.AddItem rc!TableName
rc.MoveNext
wend
end sub