473,382 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Close ODBC connection via code?

Hello All,

Is there any way to close an ODBC connection via DSN without completely
closing the Access front-end?

I'm doing some testing with using Access as a front-end to Oracle 10g
Express edition. When the user ID and password is entered on a form and
after a successful connection it seems Access doesn't change the
connection. Even if I enter an invalid user ID and/or password the
connection continues to work.

I've debug.print the connection string. It is showing the incorrect
password. I've even changed the pass-through queries connection string
via code with bogus UID and password. When I view the query properties,
it shows the bogus info. Afterward if I run the query from code it runs
no problem. If I double click the query in Access I get the ODBC
connection fail error. So for what ever reason, Access holds the
connection open when running from code.

I've done some checking and haven't found a solution. I found this more
recent link:

http://groups.google.com/group/comp....6107a1b1c06900

This link seems to indicate this is an Access problem. I don't know.
I've included the code below. Any ideals? Thanks!

=====================>Begin Code>===================================>
Sub TestQryDef()
Dim wsCur As DAO.Workspace
Dim dbCur As DAO.Database
Dim qd As DAO.QueryDef
Dim strSQL As String
On Error GoTo CheckError

Set wsCur = DBEngine.Workspaces(0)
Set dbCur = wsCur.Databases(0)
Call SetConStr
If strCnn = "" Then
Exit Sub
End If
Set qd = dbCur.QueryDefs("qrySumInvcTest")
qd.Connect = "ODBC;" & strCnn
qd.ReturnsRecords = True
DoCmd.OpenQuery "qrySumInvcTest"
qd.Connect = "ODBC;DSN=OracleXE;DATABASE=4GetU;;UID=NoGo;" & _
"PWD=4GetIt;"
qd.Close
dbCur.Close
wsCur.Close
Set qd = Nothing
Set dbCur = Nothing
Set wsCur = Nothing
Exit Sub

CheckError:
If Err.Number = 3151 Then
MsgBox "You must enter a valid UserID and Password!!!", _
vbOKOnly, "UserID and Password"
Set qd = Nothing
Set dbCur = Nothing
Set wsCur = Nothing
Exit Sub
End If
MsgBox "Error Number: " & Err.Number & " Error Desc: " & _
Err.Description, , "Error"
Set qd = Nothing
Set dbCur = Nothing
Set wsCur = Nothing
End Sub
=====================<End Code<=====================================<
=====================>Begin Code>===================================>
Sub SetConStr()
Dim strUID As String, strPswd As String
Forms("frmMain").Refresh
strCnn = ""
If IsNull(Forms("frmMain").Controls("txtUserID").Valu e) Then
MsgBox "Please enter your User ID!", , "Enter User ID"
Exit Sub
End If
If IsNull(Forms("frmMain").Controls("txtPswd").Value) Then
MsgBox "Please enter your Password!", , "Enter Password"
Exit Sub
End If
strUID = Forms("frmMain").Controls("txtUserID").Value
strPswd = Forms("frmMain").Controls("txtPswd").Value
strCnn = "DSN=OracleXE;DATABASE=XE;;" & _
"UID=" & strUID & _
";PWD=" & strPswd & ";"
Debug.Print strCnn
End Sub
=====================<End Code<=====================================<

--
Regards,

Greg Strong
Jul 9 '06 #1
3 12899
On Sun, 09 Jul 2006 01:17:16 -0500, Greg Strong
<ne*********@geedubeeu.com.invalidwrote:
>Any ideals?
Well I've tried a DSN-less connection. I got it to work to convert DSN
linked tables to DSN-less linked tables per Doug Steele's code at
http://www.accessmvp.com/djsteele/DSNLessLinks.html. However, when I
replaced the pass-through query ODBC Connect String with the following:

,----- [ pass-through query ODBC Connect String ]
| "ODBC;Driver={Oracle in XE};Dbq=XE;UID=MyUID;PWD=MyPswd;"
`-----

I get an error. It reads as follows:

,----- [ Error on pass-through query run from Access or code ]
| Reserved error(-7778); there is no message for this error
`-----

The error occurs on the following line:

,----- [ VBA error line ]
| DoCmd.OpenQuery "qrySumInvcTest"
`-----

I've tried MS's driver without luck. So I'm running out of straws to
grasp. Any ideals would be appreciated. Thanks!

The code now reads as follows:

=====================>Begin Code>===================================>
Sub TestQD_DSNless()
Dim wsCur As DAO.Workspace
Dim dbCur As DAO.Database
Dim qd As DAO.QueryDef
Dim strSQL As String
'On Error GoTo CheckError

Set wsCur = DBEngine.Workspaces(0)
Set dbCur = wsCur.Databases(0)
Call SetConStr
If strOConn = "" Then
Exit Sub
End If

Set qd = dbCur.QueryDefs("qrySumInvcTest")
qd.Connect = strOConn
qd.ReturnsRecords = True
DoCmd.OpenQuery "qrySumInvcTest"
'qd.Connect = "ODBC;DSN=OracleXE;DATABASE=4GetU;;UID=NoGo;" & _
"PWD=4GetIt;"

qd.Close
dbCur.Close
wsCur.Close
Set qd = Nothing
Set dbCur = Nothing
Set wsCur = Nothing
Exit Sub

CheckError:
If Err.Number = 3151 Then
MsgBox "You must enter a valid UserID and Password!!!", _
vbOKOnly, "UserID and Password"
Set qd = Nothing
Set dbCur = Nothing
Set wsCur = Nothing
Exit Sub
End If
MsgBox "Error Number: " & Err.Number & " Error Desc: " & _
Err.Description, , "Error"
Set qd = Nothing
Set dbCur = Nothing
Set wsCur = Nothing
End Sub
=====================<End Code<=====================================<

=====================>Begin Code>===================================>
Public strCnn As String, strOConn As String, strMSOCnn As String
=====================<End Code<=====================================<

=====================>Begin Code>===================================>
Sub SetConStr()
Dim strUID As String, strPswd As String
Forms("frmMain").Refresh
strCnn = ""
strOConn = ""
If IsNull(Forms("frmMain").Controls("txtUserID").Valu e) Then
MsgBox "Please enter your User ID!", , "Enter User ID"
Exit Sub
End If
If IsNull(Forms("frmMain").Controls("txtPswd").Value) Then
MsgBox "Please enter your Password!", , "Enter Password"
Exit Sub
End If
strUID = Forms("frmMain").Controls("txtUserID").Value
strPswd = Forms("frmMain").Controls("txtPswd").Value
strCnn = "DSN=OracleXE;DATABASE=XE;;" & _
"UID=" & strUID & _
";PWD=" & strPswd & ";"

' strOConn = "Driver={Oracle in XE};" & _
' "Dbq=XE;" & _
' "UID=" & strUID & _
' ";PWD=" & strPswd & ";"
strOConn = "ODBC;Driver={Oracle in XE};" & _
"Dbq=XE;" & _
"UID=" & strUID & _
";PWD=" & strPswd & ";"
' strOConn = "ODBC;Driver={Oracle in XE};" & _
' "DATABASE=XE;" & _
' "UID=" & strUID & _
' ";PWD=" & strPswd & ";"

strMSOCnn = "Driver={Microsoft ODBC for Oracle};" & _
"Server=DEDICATED;" & _
"UID=" & strUID & _
";PWD=" & strPswd & ";"
Debug.Print "strCnn: "; strCnn
Debug.Print "strOConn: "; strOConn
Debug.Print "strMSOCnn: "; strMSOCnn
End Sub
=====================<End Code<=====================================<
--
Best Regards,
Greg

--
Regards,

Greg Strong
Jul 9 '06 #2
Greg Strong wrote:
Well I've tried a DSN-less connection. I got it to work to convert DSN
I was dying to try DSNless when I went to A2003 from A97 two years ago.
I was bitterly disappointed in that the ADO set up would not allow me
to use DSNless connections to write Access reports, so I gave up on it
and continue to do all my Oracle stuff in DAO.

I could be wrong on the following and hope someone will jump down my
throat ASAP if I am! 8)

As far as I can tell, your PTQ won't work unless it has a DSN
connection. The ADO DSNless stuff allows you to create ADO recordsets
which are using Oracle SQL in code and have these recordsets assigned to
a form and some other objects as its recordsource (but, as I mention
above, you can't do this for reports!).

--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Jul 10 '06 #3
Greg Strong wrote:
Hello All,

Is there any way to close an ODBC connection via DSN without completely
closing the Access front-end?
I can't help with the code, but a possible suggestion might be to force
your users to enter the Oracle username password when the app turns on.
The connection string could then be checked and that would flag
whatever procedures you have that you're not connected.

As far as users having the Oracle username password, what I've done with
my major apps is create an Oracle user and grant select only access on
whatever tables I want my users to see - some of these might have insert
and other privilges besides select. I then give this user a simple
password that all users know.

Other than for perhaps people working on the app remotely, away from the
Oracle server, I can't see what reason you might have to close an ODBC
connection (that's not to say there's not a valid reason, I just can't
think of a situation in my experience where that might be necessary).
If the remote feature I describe at the beginning of this para is what
you're trying to achieve, then the above might be workable.

Another possibility in this train of thought would be to trap the Access
ODBC errors (4171 or something like that - I'm not near my Access apps
now so can't recall) that occur when the Oracle DB is not available and
have that flag the not connected state throughout the app session.
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Jul 10 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Kong Li | last post by:
Follow up to this thread, the latest Oracle 9i release 2 patchset (9.2.0.5) fixed the handle count leak problem. The problem is in Oracle client component. Thanks. Kong ----- From: Kong...
5
by: SerGioGio | last post by:
Hello, I am going nuts. I am trying to connect to my local ORACLE instance using ODBC. It used to work few weeks ago, but it fails now. Connection with: - SQL*plus: connection works! -...
7
by: Sven Schwyn | last post by:
Hi Many people are asking how to automatically update columns containing a modification date on updates. I'm wondering if the only solutions in the current pgsql really are... - adding...
5
by: Alec | last post by:
Hi All, I am currently trying to link in Access 97 to a table in a MSSQL 7 server. Initially the link is fine, however, when I close the access database and re-open it from the same network...
5
by: Mike | last post by:
I am writing a .NET application in C# that uses Crystal Reports. I want the crystal reports to grab information from a database no matter where the database is located. To do this, I want to...
8
by: Dakkar | last post by:
I wrote a program with c# for connecting mysql and taking data from it but when someone without me try to execute the program they are taking this error ERROR Data source name not found and...
4
by: mescano | last post by:
I am currently implementing a singleton pattern for accessing a database. Is it advisable to close the connection to the database at all -- thus leaving it open or should it be closed. If closed,...
8
by: Greg Strong | last post by:
Hello All, The short questions are 1 Do you know how to make DSN connection close in Access to Oracle 10g Express Edition? &/or 2 Do you know how to make a DSN-less pass-through query...
3
by: zombiechewtoy | last post by:
I'm having trouble making an ODBC connection using VB.NET 2005. I have tried nearly every connection string found on connectionstrings.com, in almost every format I can think of. I have tried...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.