Strongly Typed ConnectionString keeps disappearing

  • Thread starter Thread starter Aziz
  • Start date Start date
A

Aziz

VB 2003, Access 2000

I have been using strongly typed Datasets/database connections, it
works fine

Now, I've added a OpenFileDialog functionality to my program so the
user can select the database file.

I've added & strCon & to this code (it's a Global variable):

Me.conADOConnection.ConnectionString = "Jet OLEDB:Global Partial Bulk
Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
"ocking Mode=1;Data Source=" & strCon & ";Jet OLEDB:Engine
Type=5;" & _
"Provider=""Microsoft.Jet.OLEDB.4.0"";...........

It works fine for a while, but occasionally this whole command seems to
just disappear. It tends to happen if I add a control to my form or
make some other big change. If I paste the code back in from another
form it works fine (for a while).

Why does my connection string keep disappearing?
 
VB 2003, Access 2000

I have been using strongly typed Datasets/database connections, it
works fine

Now, I've added a OpenFileDialog functionality to my program so the
user can select the database file.

I've added & strCon & to this code (it's a Global variable):

Me.conADOConnection.ConnectionString = "Jet OLEDB:Global Partial Bulk
Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
"ocking Mode=1;Data Source=" & strCon & ";Jet OLEDB:Engine
Type=5;" & _
"Provider=""Microsoft.Jet.OLEDB.4.0"";...........

It works fine for a while, but occasionally this whole command seems to
just disappear. It tends to happen if I add a control to my form or
make some other big change. If I paste the code back in from another
form it works fine (for a while).

Why does my connection string keep disappearing?

Have you placed "Me.conADOConnection.ConnectionString = ..." inside the designer created InitComponent() method? As the
designer tends to just overwrite this section. If so try moving the connection string into the constructor after
InitComponent() and it will be left alone (although the designer may show the connection string as being blank, just
ignore that).
 
Aziz,

In addition to Chris, How and where did you put that connectionstring in
your code.

Normally I expect it in a kind of config, which depends if it is ASPNET or
Webform.

Cor
 
Thanks Chris, you were right, it was in:
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

But now I put it under "Public Sub New()" below the
InitializeComponent() method call and it works fine. I think VS put it
in InitializeComponent() automatically.

Cor:
My connection string is a public variable in a module. Anyway it's
working fine now so thanks to both of you.
 
Back
Top