473,721 Members | 1,833 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

switching ConnectionStrin g at runtime

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 ConnectionStrin g are those
generated by the Server Explorer. I can connect just fine using the
default values.

But when I comment out strDefaultConne ctionFile 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...
strDefaultConne ctionPre =
@"Provider=Micr osoft.Jet.OLEDB .4.0;Password=" """;User ID=Admin;Data
Source=";

strDefaultConne ctionFile = @"C:\Program Files\HID\Confi g
Card Production Utility\ConfigC ard.mdb";

strDefaultConne ctionPost = @";Mode=ReadWri te|Share Deny
None;Extended Properties="""" ;Jet OLEDB:System database="""";J et
OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";J et
OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global
Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1; Jet OLEDB:New
Database Password="""";J et OLEDB:Create System Database=False; Jet
OLEDB:Encrypt Database=False; Jet OLEDB:Don't Copy Locale on
Compact=False;J et OLEDB:Compact Without Replica Repair=False;Je t
OLEDB:SFP=False ";

//Code fragment of a method called to define the data
source at runtime...

if (openFileDialog 1.ShowDialog() == DialogResult.OK )
{
if ((testStream = openFileDialog1 .OpenFile()) == null)
{
testStream.Clos e();
return false;
}
//Install the new path and test it.
dbName = openFileDialog1 .FileName;
oleDbConnection 1.ConnectionStr ing =
strDefaultConne ctionPre +
// @dbName +
strDefaultConne ctionFile +

strDefaultConne ctionPost;
if (!TestConnectio n())
{
return false;
}
}
else
return false;

Feb 13 '06 #1
1 1935
In case any one is interested, I found the error.

You will note I tested the result of the users file selection by trying
to open the selected file. I neglected to close the file stream on the
success branch. That resulted in the file being open when I later
tried to connect to the database. Once I closed the filestream
everything worked fine. Thanks for the help...

Feb 15 '06 #2

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

Similar topics

4
2068
by: Jeremy Holt | last post by:
Hi, In a windows.forms application I would BeginInvoke a delegate on the UI thread to collect data from a database. When the call returns to the AsyncCallback, if the Control.InvokeRequired = True, I would then have the Control.BeginInvoke(New AsyncCallback(AddressOf GetDataCallback), New Object() {ar}). How would one achieve the same thing on an asp.net page (without using a webseervice)? In the code below, because the...
2
1505
by: AllenL | last post by:
Ever since I've been using objects with VB I've instantiated the business object from the form; the business object then creates/destroys data access layer objects as needed. The business object also maintains state for the form variables. The form unload / closing event destroys the business object. For a small set of specialized forms in .NET, I want to try switching the usual order of things. The business class will optionally...
1
1565
by: A.Neves | last post by:
Hi, I'd like to have my ConnectionString retrieved from the same place in RunTime or in DesignTime (in VS2005). Is It possible? How? Any help would be very much appreciated. Thanks.
7
1573
by: hung tran | last post by:
Hi I use the class Grouper (it's an extended WinForm GroupBox ) for all my groupboxes, but now the customer wants to be able to switch between Grouper and GroupBox at runtime, how can I do that ? My idea is making my own class like MyGroupBox and in the designer I will call something like this.groupBox2 = new MyGroupBox ();, the class MyGroupBox will then inherites / adopt either Grouper or GroupBox type at runtime, but how ?
4
12495
by: wilson | last post by:
Hi. I'm new in VB.NET. I would like to ask a question. How to change ConnectionString for DataSet at runtime? Because I want to change the dBase data file directory according to the program installed directory of user choice. The DataSet is created using wizard at design-time. Thanks for your help.
1
5739
by: garry.oxnard | last post by:
Can anyone help me to solve a problem which involves switching from Access to Excel (then back to Access) programatically please? I have an Excel template which, on open, also opens an Access database - containing a list of addresses. Sequence of events is = (1) Excel template opens in its default XXX.xls filename. (2) Code runs to save the spreadsheet as XXX.xls. (3) User clicks a button to open an Access database containing an
3
7240
by: jobs | last post by:
I've got a gridview that does not have a datasourceid assigned in the markup. I'd like to switch between two datasources in the codebehind. when I do switch, I first reset the the gridviewx.datasource = nothing and gridviewx.datasourceid = nothing before setting it to gridviewx.datasource = newdatasoruceid and then rebinding. All appears to work well until I try to excute a delete command that
1
1788
by: SamSpide | last post by:
Hi all, I have a moderate-side 'Windows Form Application' (C++) project, with several forms. For some reason switching between code & designer views (right-click ;view code' or 'view designer') is very slow. How slow? It can take more than 10 seconds for a truely moderate-size form.
3
7976
by: Michael Moreno | last post by:
Hi, We have an app that is made of many exes (WinForms and Win32 app). All those exes share and read their DB connection string from the registry. This guarantees that all the exes use the same DB. With .Net the connection string is in the app.config file as soon as you use the design time functionality to bind data to grids as an example. So when you have 20 exes you have 20 app.config and the
0
9365
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9127
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8002
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5973
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4483
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4748
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3186
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2569
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2127
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.