Reputation: 8601
I have a C# 2010 WinForms application, running on .Net Framework 3.5. This application, when launched, connects to an Access 2007 accdb database which is located in the same folder as the executable. Here is the code used to connect:
public static OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=LineWatchManager.accdb;Persist Security Info=True;Jet OLEDB:Database Password=<password here>");
public static void CreateConnection()
{
con.Open();
}
The problem I am having is that on the client's computers (Windows 7), the first time the program is launched after starting the computer, the connection to the database always fails. After that, it connects without any problems.
I have tried to get the program to attempt to connect 3 times to the database when it starts, but this does not help, even with 500 ms between attempts. I do not have this problem on my computer (either Windows 7 or 8).
After a lot of debugging attempts and many hours spent online, the only related article I found is this. Sadly no solutions in it, but since this has happened to someone not using Access, I'm guessing it's either .Net's fault or C#'s. Any help would be greatly appreciated!
EDIT: The client is not running the complete version of Access but this runtime.
Upvotes: 2
Views: 805
Reputation: 7092
Try this connectionString
, notice the |DataDirectory|
this will be the default path of your application.
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|/LineWatchManager.accdb;Persist Security Info=True;Jet OLEDB:Database Password=<password here>
Upvotes: 2
Reputation: 452
use this to create connection :
public static OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory| ...");
Upvotes: 1