MS Access to DB2 using DSN-Less Connection (1 Viewer)

bconner

Registered User.
Local time
Today, 08:10
Joined
Dec 22, 2008
Messages
183
Hi All,
I have an Access database that I want to distribute to a couple of end users. I want to create a connection that doesn't require I setup a DSN on their machines. They have access to the DB2 database.

Below is some code that connects using a Pass-Through query however it uses a DSN

Code:
Dim db As Database
Dim strLogin As Variant
Dim strPassword As Variant
strLogin = txtLogin
strPassword = txtPassword
On Error GoTo err_handler
Set db = CurrentDb
'Refresh the Pass-Thru query links based on User Name and Password entered into the Logon Form
db.QueryDefs("RevOpt_NSCs").Connect = "ODBC;DSN=HIXDB;UID=" & strLogin & ";PWD=" & strPassword & ";MODE=SHARE;DBALIAS=HIXDB;"
db.QueryDefs("RevOpt_SDCs").Connect = "ODBC;DSN=HIXDB;UID=" & strLogin & ";PWD=" & strPassword & ";MODE=SHARE;DBALIAS=HIXDB;"
MsgBox "Login Successful"
txtLogin = Null
txtPassword = Null
Exit Sub
err_handler:
MsgBox Err.Number & " " & Err.Description
I have setup DSN-Less connections to SQL Server using the below:
Using this approach I can just hand off the database to end users and as long as they have access to the SQL Server db they are good I don't have to setup DSNs etc...

Code:
db.TableDefs("dbo_Chase_Anthem").Connect = "ODBC;DRIVER=SQL Server;SERVER=VA10PWVSQL353\SQL01,10001;Trusted_Connection=YES;DATABASE=CRA;"
db.TableDefs("dbo_Chase_Anthem").RefreshLink

Any help if greatly appreciated.
 

wouter

New member
Local time
Today, 14:10
Joined
Sep 19, 2018
Messages
1
Hi, I have exactly the issue as described on this page

These are the options I tried
' Asks for DSN through dialogue...
sConnect = "ODBC;Provider=IBMDADB2;DATABASE=BLUDB;HOSTNAME=«hostname»;PORT=50000;PROTOCOL=TCPIP;UID=«username»;PWD=«password»;"
sConnect = "ODBC;Provider=DB2OLEDB;DATABASE=BLUDB;HOSTNAME=«hostname»;PORT=50000;PROTOCOL=TCPIP;UID=«username»;PWD=«password»;"

' ODBC call failed
sConnect = "ODBC;Driver=IBM DB2 ODBC DRIVER - C_PROGRA~1_IBM_V10~2.5FP;DATABASE=BLUDB;HOSTNAME=«hostname»;PORT=50000;PROTOCOL=TCPIP;UID=«username»;PWD=«password»;"
sConnect = "ODBC;Driver={IBM DB2 ODBC DRIVER - C_PROGRA~1_IBM_V10~2.5FP};DATABASE=BLUDB;HOSTNAME=«hostname»;PORT=50000;PROTOCOL=TCPIP;UID=«username»;PWD=«password»;"
sConnect = "ODBC;Driver='IBM DB2 ODBC DRIVER - C_PROGRA~1_IBM_V10~2.5FP';DATABASE=BLUDB;HOSTNAME=«hostname»;PORT=50000;PROTOCOL=TCPIP;UID=«username»;PWD=«password»;"
sConnect = "ODBC;Driver={IBM DB2 ODBC DRIVER};DATABASE=BLUDB;HOSTNAME=«hostname»;PORT=50000;PROTOCOL=TCPIP;UID=«username»;PWD=«password»;"
sConnect = "ODBC;Driver={IBM DB2 ODBC DRIVER};DBALIAS=BLUDB;HOSTNAME=«hostname»;PORT=50000;PROTOCOL=TCPIP;UID=«username»;PWD=«password»;"

' Error -7778
sConnect = "ODBC;Driver=IBM DB2 ODBC;DATABASE=BLUDB;HOSTNAME=«hostname»;PORT=50000;PROTOCOL=TCPIP;UID=«username»;PWD=«password»;"

' This works, because DSN exists
sConnect = "ODBC;DSN=BLUDB;DATABASE=BLUDB;HOSTNAME=«hostname»;PORT=50000;PROTOCOL=TCPIP;UID=«username»;PWD=«password»;"
sConnect = "ODBC;DSN=BLUDB4ACCESS;DATABASE=BLUDB;HOSTNAME=«hostname»;PORT=50000;PROTOCOL=TCPIP;UID=«username»;PWD=«password»;"


Only when specifying DSN (which must exist) it works

MS Access code:
Set tdf = CurrentDb.CreateTableDef("db2_USERS")
tdf.SourceTableName = "USERS"
tdf.Connect = sConnect
CurrentDb.TableDefs.Append tdf
 

isladogs

MVP / VIP
Local time
Today, 14:10
Joined
Jan 14, 2017
Messages
18,216
I don't use DB2 but do you need to include PORT & PROTOCOL in your connection strings? Have you tried omitting these?

These aren't included in most of the examples in the link provided by ByteMizer
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 21:10
Joined
May 7, 2009
Messages
19,237
if you can Google DB2 Connection string, there are plenty to try.
 

Users who are viewing this thread

Top Bottom