Runtime Error '3709' while accesing SQL database in VB6 - sql

I have a VB6 application which someone wrote, which does not work for only some users who try to use it.
This is the code running which returns an error:
On Error GOTO error_handler
..
Set db = New ADODB.Connection
db.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=****;Password=****; Initial Catalog=***;Data Source=****,1433"
error_handler:
If db.Error.count then
strDBErrors = "No access to Main Database."
For Each err In db.errors
strDBErrors = strDBErrors & vbCrLf & err.Description
Next
MsgBox strDBErrors
After this code runs, I get two Boxes of error. One which states a Runtime Error 3709, And the other which has Two lines: one of it is my Custom error message, and the second if this: "Logon Failed for user the user".
This only happens to one user on a specific computer on which this program is installed. It does not happen on any other computer with any other user.
I tried reinstalling the program with that user on that computer, but it did not work.
Any ideas?

Not quite sure what the problem was,
but I just erased the user on Active Directory and created it again, and it worked.
The user wasn't a member of any deny groups though.

Related

Need advice with Error Handling for Invalid Path

I could use some advice on how to handle a strange issue that happens to my users.
Issue:
All of my users are on laptops that use VPN to connect to our network. When they disconnect from the VPN and reconnect the network drive also disconnects till they open the drive or folder through file explorer. When this happens and they don't re-establish the connection to the network drive they end up with 3304 error.
Error Handling?
What I'd like to do is setup some sort of error handler to tell them thats what happened with a potential link they could click on to re establish the connection. OR even better just have the VBA code identify that error 3304 has occurred and re-establish the connection automatically for them and no pop up error happen at all.
Has anyone done this? I've done some research but nothing I've found quite fits the criteria for this issue. Looking for any advice or push in the right direction.
I was thinking of something like this where either they get a pop up with a link or skip the pop up all together and find a way to re-connect the drive in the background.
On Error GoTo ErrHandler
'Error Handler
ErrHandler:
If Err.Number = 3304 Then
MsgBox "Error Number:" & Err.Number & vbCrLf & _
"Error Description: " & Err.Description & vbCrLf & _
"This error is due to your VPN being disconnected and reconnected"
Else
End If
We faced that issue a couple months ago. We took the route of actually just showing an informative MsgBox to tell the users what to do to solve by themselves calling a function into the 'Workbook_Open' event that fails if a Central Code for the Company its not found with the Dir() function:
Function IsVPNOn(ByVal strCentralCodePath As String) As Boolean
Dim retBoolean As Boolean
On Error Resume Next
If IsError(Dir(strCentralCodePath & g_strCentralCodeName)) Then
MsgBox "The VPN seems to be disconnected." & vbCr & vbCr & _
"Please check VPN connection if Company toolbar is needed.", _
vbCritical + vbOKOnly, "Company Ribbon"
retBoolean = False
Else
retBoolean = True
End If
IsVPNOn = retBoolean
End Function
Not gonna lie, the second option with skipping and reconnecting without the user being even aware of the problem seems more classy, but it is way trickier as you have to deal with connections inside your code.

Object with special character "/" produces Automation Error in GetObject

We have an old Microsoft Access font end that serves as the GUI to our user database. I was never much of a VBA person so as I go through fixing bugs I'm learning as I go.
Our Access DB has a number of commands to sync info to Active Directory. One such command is to add a user to a group. However, whenever the group contains a / the group is never added.
The debug produces this as:
Run-time error -2147463168 (80005000)': Automation Error".
Printing out the targetgroup shows the DN as I expect it. Trying to escape the / before the GetObject doesn't help and causes its own auth error.
Here's the top part of the function -
Function AddGroup(TargetGroup, strUserID, Optional strOptReqBy)
Dim objDL
Set objUser = GetObject("LDAP://" & GetDName(CStr(strUserID)))
Set objDL = GetObject("LDAP://" & TargetGroup)
On Error Resume Next
objDL.Add (objUser.ADsPath)
objDL.SetInfo
On Error GoTo 0
This works fine if the group does not contain a /.
Debug points to Set objDL = GetObject("LDAP://" & TargetGroup)
Looking for some input on why this is happening. Thanks!
In an LDAP path, the / is a separator. Not only is the // used near the beginning, but you can also specify the server you want to connect to, followed by a /, then the DN of the object, like this:
LDAP://example.com/DC=example,DC=com
That's necessary if the computer you're running this from isn't not joined to the same (or trusted) domain than the domain you're connecting to.
So that means that if the DN of the object you want to bind to has a /, it will think that everything before the / is a server to connect to and it explodes.
So you just need to escape it, which, as you've already learned, is done with a \:
LDAP://OU=This\/That,DC=example,DC=com
So yeah, a simple replace will do:
Set objUser = GetObject("LDAP://" & Replace(GetDName(CStr(strUserID)), "/", "\/")
Don't feel bad. Even Microsoft has this bug in their code.

application run method "error application-defined or object-defined error"

I'm trying to run a sub for access using the Access.application.run method. It keeps on bringing up error:
40351 "error application-defined or object-defined error"
The code is very basic:
Dim objAccess, wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Set objAccess = CreateObject("Access.Application")
With objAccess
.OpenCurrentDatabase ("c:\coxi\Documents\Personnal\investment\5334_2.accdb")
.Run "test"
Set .CurrentProject = Nothing
End With
the routine errors on the .run line
Root cause: Your code is trying to open un-trusted access DB "5334_2.accdb"
Fix:
Open access application
Goto Trusted center settings under options.
Add the location of the Access DB file.
Retry executing the code.
Thanks a lot !
I had the same hidden problem and could resolve it this way!
I edited code in an .accdb database on the C: drive (C:\…\…\…) and signed the Word templates. Everything worked well, including some Word integration in both directions (Word calling Access procedures and conversely).
When I copied the Access database and the Word templates onto my standard database path (D:\…\…), both the Access database and the Word templates performed well, with the exception of error 40351 in Word on the AccessObj.run "Myproc" …
A pity that neither Word nor Access display a dialog to enable the Access code or at least a sound error message.

VBA ADO: Could Not Use <Filename>; file already in use

It's been a long time since I've had to do any development in Access, so hoping I can get some help. I have a split Front End/Back End solution that I've built. The Back End resides on a server, the front end gets copied down to user's desktops (and they use runtime Access 2013). I'm using Access with VBA and ADO connections/recordsets in order to do all record actions (Select, inserts, updates mostly).
Two intermittent issues have cropped up and I'm at a loss - this is one of them. From time to time, some users will get the error "Could not use "(back end Filename)"; file already in use." (where (back end filename) is my back end db name & location". When users get this message, they close out, re-open and try the same data entry and it works without a hitch. Here's the code:
Private Sub SetProblemCode()
On Error GoTo ErrorHandler
strSQL = "SELECT Problem_Code_ID, Problem_Code, Problem_Description FROM Problem_Code ORDER BY Problem_Description"
con.Open strConString
rstProblemCode.CursorLocation = adUseClient
rstProblemCode.Open strSQL, con, adOpenForwardOnly, adLockReadOnly
cboProblemCode.RowSourceType = "Table/Query"
Set cboProblemCode.Recordset = rstProblemCode
rstProblemCode.Close
con.Close
Exit Sub
ErrorHandler:
CriticalError Err.Description, Err.Number, Me.Name, "SetProblemCode"
End Sub
The rst and con objects are defined at the global level, a practice I've used in other solutions before but I'm questioning if that's some of the problem. I'm also questioning the cursor location, type and lock type I'm using, although it seems correct - I'm not altering data, just copying a recordset to the Access combo box.
I'm hesitant to make sweeping changes when it seems like the user closes out and tries again and it works just fine. Any thoughts?

VBA Excel won't connect to Access DB on another computer

A colleague of mine is trying to use an excel tool that pulls data from an access database. The tool works perfectly on my computer but he is having the issue that the tool is unable to connect with the Access database.
I've tried solving the problem by checking that the excel options are correct i.e. making sure macros are enabled etc. but I'm still getting the problem.
The problem must be something in my colleagues settings that hasn't been configured because the tool works without any issues for me. Here are some of the parts of the code that read the Access DB:
Public Const pActuarialPWD = "password2"
Public Const QuoteDB = "N:\DWH\Commercial Ins\Fleet\Databases\Quote DB.accdb"
If bDBOpen = False Then
'Connect to database
If openQuotedb() = False Then
MsgBox "Connection to database failed - contact Actuarial"
Exit Sub
End If
End If
Function openQuotedb()
On Error GoTo ErrorHandler
openQuotedb = False
Set db = OpenDatabase(QuoteDB, False, False, "MS Access;PWD=" & pActuarialPWD)
openQuotedb = True
Exit Function
ErrorHandler:
MsgBox "Couldn't connect to database. Please contact actuarial. Tool should not be used, as quote information will be lost", vbCritical
End Function
I've stepped through the program both in my computer and my colleagues a number of times and I can't see what the problem is. When I step past the line of code "db = ..." on my colleagues PC and hover over db it reads "db = Nothing" whereas on mine it successfully connects to the database.
Have you any ideas what might be going wrong here. It just seems exces is not setup properly to connect to Access on my colleagues PC.
The only thing I can think of is that I am using Excel 2013 and my colleague is on 2010.
The function below have saved me a lot of trouble. I don't know if it will solve your problem but in general will help.
I have tested it in many applications and with a variety of changes and variables and it worked every time and has never failed me. Maybe will help you.
Public Function db_connect(Optional sel_db As Variant = "", Optional pass_be As Variant = ";PWD=<password>") As DAO.Database
Dim db As DAO.Database
If sel_db = "" Then
sel_db = "<database_path>"
End If
On Error GoTo db_locked:
Set db = DBEngine.OpenDatabase(sel_db, True, False, pass_be)
GoTo DBclose:
db_locked:
Sleep 100
Set db = DB_Connection.db_connect(sel_db, pass_be)
DBclose:
Set db_connect = db
End Function
To call the function just do:
Dim db As DAO.Database
Set pers = DB_Connection.db_connect("full_path or your path with the N drive mapped", ";PWD=<db_password>")
WARNING-DISCLAIMER!!!
Be careful. The function has a waiting mechanism and tries to connect without never stoping. If you have wrong parameters or the database doesn't exist then it will stuck in an infinite loop. I never bothered to fix it because I knew the problem and avoid it. However, you can make improvements if you want.