T
TeeCo
Hi folks. I'm trying to change the location of the Access mdb file I
connect to using OleDb and am having trouble. I'm using Visual C# 2005
and the default values I use for the ConnectionString are those
generated by the Server Explorer. I can connect just fine using the
default values.
But when I comment out strDefaultConnectionFile and uncomment the
dbName variable I get:
'OleDbException: Could not use "; file already in use.' During testing
I select the exact same path and file that are used in the default, and
I have confirmed this by copying both 'runtime' strings to a text file
and comparing them.
So the two strings are identical. But the 2nd fails. Of course, I
close the debugger when switching between strings and have confirmed
that there are no locks on the database. And access permissions are
the same for the mdb in both cases. I am baffled!
Code fragments are below. Any help would be appreciated.
//Three strings defined earlier in the code...
strDefaultConnectionPre =
@"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data
Source=";
strDefaultConnectionFile = @"C:\Program Files\HID\Config
Card Production Utility\ConfigCard.mdb";
strDefaultConnectionPost = @";Mode=ReadWrite|Share Deny
None;Extended Properties="""";Jet OLEDB:System database="""";Jet
OLEDB:Registry Path="""";Jet OLEDBatabase Password="""";Jet
OLEDB:Engine Type=5;Jet OLEDBatabase Locking Mode=1;Jet OLEDB:Global
Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New
Database Password="""";Jet OLEDB:Create System Database=False;Jet
OLEDB:Encrypt Database=False;Jet OLEDBon't Copy Locale on
Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet
OLEDB:SFP=False";
//Code fragment of a method called to define the data
source at runtime...
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
if ((testStream = openFileDialog1.OpenFile()) == null)
{
testStream.Close();
return false;
}
//Install the new path and test it.
dbName = openFileDialog1.FileName;
oleDbConnection1.ConnectionString =
strDefaultConnectionPre +
// @dbName +
strDefaultConnectionFile +
strDefaultConnectionPost;
if (!TestConnection())
{
return false;
}
}
else
return false;
connect to using OleDb and am having trouble. I'm using Visual C# 2005
and the default values I use for the ConnectionString are those
generated by the Server Explorer. I can connect just fine using the
default values.
But when I comment out strDefaultConnectionFile and uncomment the
dbName variable I get:
'OleDbException: Could not use "; file already in use.' During testing
I select the exact same path and file that are used in the default, and
I have confirmed this by copying both 'runtime' strings to a text file
and comparing them.
So the two strings are identical. But the 2nd fails. Of course, I
close the debugger when switching between strings and have confirmed
that there are no locks on the database. And access permissions are
the same for the mdb in both cases. I am baffled!
Code fragments are below. Any help would be appreciated.
//Three strings defined earlier in the code...
strDefaultConnectionPre =
@"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data
Source=";
strDefaultConnectionFile = @"C:\Program Files\HID\Config
Card Production Utility\ConfigCard.mdb";
strDefaultConnectionPost = @";Mode=ReadWrite|Share Deny
None;Extended Properties="""";Jet OLEDB:System database="""";Jet
OLEDB:Registry Path="""";Jet OLEDBatabase Password="""";Jet
OLEDB:Engine Type=5;Jet OLEDBatabase Locking Mode=1;Jet OLEDB:Global
Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New
Database Password="""";Jet OLEDB:Create System Database=False;Jet
OLEDB:Encrypt Database=False;Jet OLEDBon't Copy Locale on
Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet
OLEDB:SFP=False";
//Code fragment of a method called to define the data
source at runtime...
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
if ((testStream = openFileDialog1.OpenFile()) == null)
{
testStream.Close();
return false;
}
//Install the new path and test it.
dbName = openFileDialog1.FileName;
oleDbConnection1.ConnectionString =
strDefaultConnectionPre +
// @dbName +
strDefaultConnectionFile +
strDefaultConnectionPost;
if (!TestConnection())
{
return false;
}
}
else
return false;