ADODB Connection String: Workgroup Information file is Missing? - ms-access

I have a few data sources in access that I need to connect to programatically to do things with behind the scenes and keep visibility away from users.
Said datasource has a password 'pass' as I'm going to call it here. Using this connection method I get an error attempting to use the open method
Dim conn as ADODB.Connection
Set ROBBERS.conn = New ADODB.Connection
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=\\pep-home\projects\billing\autobilling\DPBilling2.mdb;" _
& "Jet OLEDB:Database Password=pass;", "admin", "pass"
"Cannot start your application. The workgroup information file is missing or opened exclusively by another user."
Due to planning to move into 2007, we are not using nor have ever used a workgroup identification file through access. The database password on the data source was set through the Set Databa Password which had to be done on an exclusive open.
Ive spent a good while changing around my connection options, where to put the passwords etc and either cannot find the right format, or (why I'm asking here) I think there may be some other unknown that I must setup to do this. Anyone out there got some useful information?

Your connection string seems to be incorrect. Try:
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=\\pep-home\projects\billing\autobilling\DPBilling2.mdb;" _
& "Jet OLEDB:Database Password=MyDbPassword;"
-- http://www.connectionstrings.com/access

Related

Failed VBA SQL Query in Outlook 365?

I have some VBA code in Outlook that runs a SQL query and populates a userform I designed. This code was previously running fine on one PC, then I was issued a new laptop and I copied the outlook VBA module directly over.
When I try to run, I just get an error "Compile Error: Can't find project or library" and the text "adOpenStatic" in the RS.open statement is highlighted. Previously, I had seen the same error if my SQL query was bad or the driver was missing, but I double checked both. I copied the EXACT code into an excel VBA module and it ran as expected.
The only other difference I can see is that I went from Outlook 2019 to Office 365 for Enterprise.
Dim server, database, login_user, password, port As String
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSQL As String
server = "dummy"
database = "dummy"
login_user = "dummy"
password = "dummy"
port = "dummy"
Set cn = New ADODB.Connection
cn.ConnectionString = "DRIVER={MySQL ODBC 8.0 ANSI Driver};Provider=MSDASQL;" & "SERVER=" & server & ";" & " DATABASE=" & database & ";" & "UID=" & login_user & ";PWD=" & password & "; OPTION=3; PORT=" & port & ";Connect Timeout=20;"
'open the connection
cn.Open
Set rs = New ADODB.Recordset
strSQL = "SELECT * FROM quote WHERE id = 1505"
rs.Open strSQL, cn, adOpenStatic
With rs
Do Until .EOF
'parse out relevant project information
rs.MoveNext
Loop
End With
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
I can run the exact query in MySQL workbench, and it works as expected. The fact that the identical code can run in Excel without issue tells me there is perhaps a syntax difference in Outlook that I am unaware of? Anyone else have ideas?
NOTE, if it wasn't already obvious, I am omitting my database details with "Dummy", but the real code has the correct strings.
This code was previously running fine on one PC, then I was issued a new laptop and I copied the outlook VBA module directly over.
You need to re-add all COM references you had on the old machine.
From the Tools menu, choose References to display the References dialog box.
The References dialog box shows all object libraries registered with the operating system. Scroll through the list for the application whose object library you want to reference. If the application isn't listed, you can use the Browse button to search for object libraries (*.olb and .tlb) or executable files (.exe and *.dll on Windows). References whose check boxes are selected are used by your project; those that aren't selected are not used, but can be added.
Go to the VBA Editor, and choose Tools-References; and tick the box next to 'Microsoft ActiveX Data Objects' (the latest version). It should compile ok now.

Connection to MSAccess DB unable to perform more than one query

I'm setting up my first locally hosted website on a new machine in a long time and to be honest am not very familiar with all the manual settings that get configured now. My last set up was on a Windows XP box and it seemed to "just work" when I enabled IIS. Not so this time.
My latest issues is with connecting to a MSAccess DB. I have a VERY BASIC page with a form that contains 1 input. I check the DB to make sure it doesn't already contain the value and if not, then write the value to the DB. I get the following error:
Provider error '80004005'
Unspecified error
/trips/admin_add_hotel.asp, line 22
I've researched online and everything seems to point to it being a permissions issue. However, I can remove the second portion of the code (the writing) and the page will return fine. If I try to run the page again or refresh, I'll then get the error. This to me says the user has read access. Now, I can wait a little bit and remove the first portion of the code and just write to the DB and it will work fine. Again, to me signifying that the user has write access. However, if I try to run it again... same error.
Here's the ASP code:
<!--#include file="includefile.asp"-->
<%
if Request("action") = "submit" then
'make sure hotel name is filled in
if Request("fhotel") <> "" then
fhotel = Request("fhotel")
'make sure hotel doesn't already exist in DB
sql = "SELECT hotel_id FROM hotels WHERE hotel_name = '" & Replace(fhotel, "'", "''") & "'"
RS.Open sql, ConnectString
if NOT RS.EOF then
Session("msg") = "Hotel already exists"
End if
RS.Close
'add hotel to DB
if Session("msg") = "" then
sql = "INSERT INTO hotels (hotel_name) VALUES ('" & Replace(fhotel, "'", "''") & "')"
Conn.Open ConnectString
Conn.Execute sql
Conn.Close
Session("msg") = "Hotel added successfully"
fhotel = ""
End if
Else
Session("msg") = "Hotel left blank"
End if
Set RS = Nothing
Set Conn = Nothing
End if
%>
My include file is:
<%
ConnectString = "DSN=ConnectionDSN; Uid=username; Pwd=password"
Set RS = Server.CreateObject("ADODB.Recordset")
Set Conn = Server.CreateObject("ADODB.Connection")
%>
My DB has 1 table with two columns:
hotel_id [AUTONUMBER]
hotel_name [TEXT (255)]
Here are my system details:
Windows 7 Pro 64-bit (although connections have been set up for 32-bit based on what I've found online)
IIS 7.5
Just to make sure it wasn't a permissions issue, I've temporarily allowed the 'Everyone' user full access to that folder.
Any help is appreciated. I believe this is the last hurdle I have to get thing fully up and running.
Thanks in advance.
A few things:
32bit vs 64bits: make absolutely sure that your application is set explicitly to x86, not AnyCPU. Also make sure that if you are using the newer .accdb you have the Access Database Engine drivers installed.
Permissions: as Dan Matheus said, make sur that the process under which IIS runs has write permission to the folder. It may not be enough that you set it to Everyone, make sure that your web app can actually create a file in that folder (test this assumption in your code).
Make sure your connection string for the Access file explicitly mentions shared access, and not exclusive access, otherwise, if different processes have the
Keep a connection to the database open all the time to avoid issues with the quick creation/deletion of the lock file.
The Jet/ACE database driver needs to create the lock file every time you access the file (if it is in shared mode). Issues will arise when your app quickly access/releases the database file and the lock file is created/deleted too often.
First it will greatly slow down your performance, and second you will get strange errors.
Just keep a connection open to the database and close it when your app shutdowns.
For more information about the points above, see this:
Intermittent “System resource exceeded” exception for OleDB connection to Microsoft Access data file

Is it possible to use VBA to change the Current accdb/e Database password

I have a personal DB app that was initially designed using the mdb format in Access 2007. For security reasons I've converted it to .accdb. All functions converted fine except the change DB password function. This function is done in VBA because the Db has all the tool bars turned off. In mdb format... this works fine
DBPath = [CurrentProject].[FullName]
' Create connection string by using current password.
strOpenPwd = ";pwd=" & OldPswd
' Open database for exclusive access by using current password. To get
' exclusive access, you must set the Options argument to True.
Set dbsDB = OpenDatabase(Name:=DBPath, _
Options:=True, _
ReadOnly:=False, _
Connect:=strOpenPwd)
' Set or change password.
With dbsDB
.NewPassword OldPswd, Pswd2
.Close
End With
Me.DB_Pswd = Pswd2
Set dbsDB = Nothing
I found something from this very forum that comes close for the .accdb but it only works for another .accdb file not the current project....
strAlterPassword = "ALTER DATABASE PASSWORD [" & NwPswd& "] [" & OldPswd & "];"
Set ADO_Cnnct = New adodb.Connection
With ADO_Cnnct
.Mode = adModeShareExclusive
.Provider = "Microsoft.ACE.OLEDB.12.0"
' Use old password to establish connection
.Properties("Jet OLEDB:Database Password") = OldPswd
'name current DB
DBPath = [CurrentProject].[FullName] <- this does not work: get a file already in use error
.Open "Data Source= " & DBPath & ";"
' Execute the SQL statement to change the password.
.Execute (strAlterPassword)
End With
'Clean up objects.
ADO_Cnnct.Close
Set ADO_Cnnct = Nothing
So is there a way to do this in VBA for .accdb files? Basically it would be automating the tool bar function of first Decrypt and the encrypt with a new password. I know the tool bar can do so I know there must be a VBA way to do it.
I found the fix for this or maybe just a work around. By removing the ADO library the first method will work for .Accde format files. It will not work for the .accdb format file, but you don't want to distribute those anyway.

Scripting access to an Access file with a security Workgroup file

I am trying to script access to an Access database for use on the command line. The Access database is secured with a workgroup file.
Dim oApp, sWGF,myWS
Set sApp = CreateObject("Access.Application")
set sWGF = "C:\Users\Alan\Documents\Secured.mdw"
oApp.DBEngine.SystemDb = sWGF
WScript.echo "Workgroup " & sWGF
WScript.echo "SystemDb " & oApp.DBEngine.SystemDb
Set myWS = oApp.DBEngine.CreateWorkspace("New","Name","Password")
This code outputs the Secured.mdw filename for the workgroup, but the default System.mdw filename for the SystemDB as the output from the two WScript.echo commands. It also fails to create the workspace saying the Name and Password are wrong (although they ARE correct for the Secured.mdw file)
There are lots of references elsewhere on the net that say you can only do this as the first thing inside an application, but that IS what I am doing.
I am not sure what I am doing wrong. Any ideas
I think you should be using DAO and Jet directly, instead of automating Access.
Dim objEngine
Dim strWorgroup
dim wrkWorkspace
Dim db
Set objEngine = CreateObject("DAO.DBEngine.36")
objEngine.SystemDB = "C:\Users\Alan\Documents\Secured.mdw"
Set wrkWorkspace = objEngine.CreateWorkspace("", "Name", "Password")
Set db = wrkWorkspace.OpenDatabase("C:\MyDatabase.mdb")
This would bypass Access itself and use the Jet database engine directly, which seems simpler to me.
In testing this, I had some difficulty setting the SystemDB as well, but it turned out I just had to make sure I was providing a VALID one for use. The first non-default one I tried didn't work, but when I made a copy of the default one and used that, it worked.
So, I'd look to see if you've got the correct filename/path for your workgroup file, if it's the right version of Jet, and if you've got the appropriate NTFS permissions to open it.
Are sApp and oApp the same thing? You're mixing up variables.
A late addition to "I had some difficulty setting the SystemDB as well":
This worked for me:
Set objEngine = CreateObject("DAO.PrivateDBEngine.36")

Connect SQL Server Compact 3.5 Database to MS Access 2003 using ADO?

Is it possible to write connect and open a SQL Compact 3.5 database from within MS Access 2003? I want to be able to use MS Access 2003 to manipulate data in a SQL Compact 3.5 database. If it is possible, then what statements would be used to open the database?
This is just an idea and I can't confirm that it will work, but given that SQL Compact lacks an ODBC driver and you can't have linked tables, perhaps you can use an OLEDB connect string for SQL Compact as the Source Connect String of a saved QueryDef in Access. If you can get that to work you may be able to create a saved QueryDef for each table, and then utilize them as though the queries were linked tables.
I can't test it on my machine because the only OLEDB provider I have installed is Jet, and Access doesn't seem to like that.
But it might be worth a try. Possibly it's not going to work, as I can't find anywhere that anyone has done this in Access. But I don't really see why it shouldn't work.
Again, I could simply be wrong, though.
Though I did not try it specifically with SQL Compact, connecting to the server should be standard:
Check that the ADODB file (msado21.tlb) is correctly refernced in your available tools
Write down your connection string somewhere like this one:
MyConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=YourDatabaseName;Data Source=YourSQLServerInstanceName"
This string is written for an 'integrated security' context. In cas you want to change it for an SQL security context, please check here to update the string. Ideally, this string should be declared as a public variable in your code.
Once this is done, you can open an ADODB recordset and begin to manipulate it:
public sub connectionTest
Dim activeConnection as ADODB.connection, _
activeRecordset as ADODB.recordset
Set activeConnection = New ADODB.connection
activeConnection.connectionString = myCOnnectionString
activeConnection.open
set activeRecordset = New ADODB.recordset
'this will open a read-only recordset'
activeRecordset.open _
"SELECT * FROM myTableName", _
activeConnection, _
adOpenStatic, _
adLockReadOnly
if activeRecordset.EOF and activeRecordset.BOF then
debug.print "No records in this table"
else
activeRecordset.moveFirst
do while not activeRecordset.EOF
debug.print activerecordset.fields("myFieldName").value
activeRecordset.moveNext
loop
endif
activeRecordset.close
set activeRecordset = nothing
activeConnection.close
set activeConnection = nothing
end sub