Home All Groups Group Topic Archive Search About

Using a Variable within a Connection String

Author
14 Feb 2007 5:14 PM
pooba53
Take a gander:

Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global
Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
        "ocking Mode=1;Data Source=""AppBase"";Jet OLEDB:Engine
Type=5;Provider=""Mic" & _
        "rosoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet
OLEDB:SFP=False;persist sec" & _
        "urity info=False;Extended Properties=;Mode=Share Deny
None;Jet OLEDB:Encrypt Dat" & _
        "abase=False;Jet OLEDB:Create System Database=False;Jet
OLEDB:Don't Copy Locale o" & _
        "n Compact=False;Jet OLEDB:Compact Without Replica
Repair=False;User ID=Admin;Jet" & _
        " OLEDB:Global Bulk Transactions=1"

I would like to use a string contained in a variable for the Data
Source in the above example. In the above example the variable is
called "AppBase". No matter what I do with regard to quotes, no
quotes, single quotes, etc. the value of the string is never
substituted in. It remains "AppBase".

Is there some syntax that will allow me to use the contents of a
variable in my connection string?

Thanks.

Author
14 Feb 2007 5:27 PM
Norman Yuan
"...Data Source=" & AppBase & ";Jet OLEDB:Engine..."

Assume AppBase is declared as String and holds a valid content.

Show quote
"pooba53" <poob***@gmail.com> wrote in message
news:1171473240.219144.3100@h3g2000cwc.googlegroups.com...
> Take a gander:
>
> Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global
> Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
>        "ocking Mode=1;Data Source=""AppBase"";Jet OLEDB:Engine
> Type=5;Provider=""Mic" & _
>        "rosoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet
> OLEDB:SFP=False;persist sec" & _
>        "urity info=False;Extended Properties=;Mode=Share Deny
> None;Jet OLEDB:Encrypt Dat" & _
>        "abase=False;Jet OLEDB:Create System Database=False;Jet
> OLEDB:Don't Copy Locale o" & _
>        "n Compact=False;Jet OLEDB:Compact Without Replica
> Repair=False;User ID=Admin;Jet" & _
>        " OLEDB:Global Bulk Transactions=1"
>
> I would like to use a string contained in a variable for the Data
> Source in the above example. In the above example the variable is
> called "AppBase". No matter what I do with regard to quotes, no
> quotes, single quotes, etc. the value of the string is never
> substituted in. It remains "AppBase".
>
> Is there some syntax that will allow me to use the contents of a
> variable in my connection string?
>
> Thanks.
>
Author
14 Feb 2007 6:53 PM
pooba53
Hey, that worked like a charm! Thanks a million ;-)

One thing I noticed, however, is that the portion of the code where
I'm editing is in the "Windows Form Designer generated code" portion.
This is where the connection string is. For some reason my code
disappears after a few runs.

I'm wondering how I can get around this problem.

-Dan

Show quote
On Feb 14, 11:27 am, "Norman Yuan" <NotR***@NotReal.not> wrote:
> "...Data Source=" & AppBase & ";Jet OLEDB:Engine..."
>
> Assume AppBase is declared as String and holds a valid content.
>
> "pooba53" <poob***@gmail.com> wrote in message
>
> news:1171473240.219144.3100@h3g2000cwc.googlegroups.com...
>
> > Take a gander:
>
> > Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global
> > Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
> >        "ocking Mode=1;Data Source=""AppBase"";Jet OLEDB:Engine
> > Type=5;Provider=""Mic" & _
> >        "rosoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet
> > OLEDB:SFP=False;persist sec" & _
> >        "urity info=False;Extended Properties=;Mode=Share Deny
> > None;Jet OLEDB:Encrypt Dat" & _
> >        "abase=False;Jet OLEDB:Create System Database=False;Jet
> > OLEDB:Don't Copy Locale o" & _
> >        "n Compact=False;Jet OLEDB:Compact Without Replica
> > Repair=False;User ID=Admin;Jet" & _
> >        " OLEDB:Global Bulk Transactions=1"
>
> > I would like to use a string contained in a variable for the Data
> > Source in the above example. In the above example the variable is
> > called "AppBase". No matter what I do with regard to quotes, no
> > quotes, single quotes, etc. the value of the string is never
> > substituted in. It remains "AppBase".
>
> > Is there some syntax that will allow me to use the contents of a
> > variable in my connection string?
>
> > Thanks.
Author
15 Feb 2007 1:32 PM
Otis Mukinfus
Show quote
On 14 Feb 2007 10:53:42 -0800, "pooba53" <poob***@gmail.com> wrote:

>Hey, that worked like a charm! Thanks a million ;-)
>
>One thing I noticed, however, is that the portion of the code where
>I'm editing is in the "Windows Form Designer generated code" portion.
>This is where the connection string is. For some reason my code
>disappears after a few runs.
>
>I'm wondering how I can get around this problem.
>
>-Dan
>
>On Feb 14, 11:27 am, "Norman Yuan" <NotR***@NotReal.not> wrote:
>> "...Data Source=" & AppBase & ";Jet OLEDB:Engine..."
>>
>> Assume AppBase is declared as String and holds a valid content.
>>
>> "pooba53" <poob***@gmail.com> wrote in message
>>
>> news:1171473240.219144.3100@h3g2000cwc.googlegroups.com...
>>
>> > Take a gander:
>>
>> > Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global
>> > Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
>> >        "ocking Mode=1;Data Source=""AppBase"";Jet OLEDB:Engine
>> > Type=5;Provider=""Mic" & _
>> >        "rosoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet
>> > OLEDB:SFP=False;persist sec" & _
>> >        "urity info=False;Extended Properties=;Mode=Share Deny
>> > None;Jet OLEDB:Encrypt Dat" & _
>> >        "abase=False;Jet OLEDB:Create System Database=False;Jet
>> > OLEDB:Don't Copy Locale o" & _
>> >        "n Compact=False;Jet OLEDB:Compact Without Replica
>> > Repair=False;User ID=Admin;Jet" & _
>> >        " OLEDB:Global Bulk Transactions=1"
>>
>> > I would like to use a string contained in a variable for the Data
>> > Source in the above example. In the above example the variable is
>> > called "AppBase". No matter what I do with regard to quotes, no
>> > quotes, single quotes, etc. the value of the string is never
>> > substituted in. It remains "AppBase".
>>
>> > Is there some syntax that will allow me to use the contents of a
>> > variable in my connection string?
>>
>> > Thanks.
>

Never make changes to the Application generated code.  Make your changes after
the InitializeComponent() call in the Form's constructor.  Doing so will
override any settings created or set in the InitiailzeComponent method.

Good luck with your project,

Otis Mukinfus

http://www.otismukinfus.com
http://www.arltex.com
http://www.tomchilders.com
http://www.n5ge.com
Author
18 Feb 2007 11:34 PM
pooba53
On Feb 15, 7:32 am, Otis Mukinfus <phoney.email.addr***@phoney.com>
wrote:
Show quote
> On 14 Feb 2007 10:53:42 -0800, "pooba53" <poob***@gmail.com> wrote:
>
>
>
> >Hey, that worked like a charm! Thanks a million ;-)
>
> >One thing I noticed, however, is that the portion of the code where
> >I'm editing is in the "Windows Form Designer generated code" portion.
> >This is where the connection string is. For some reason my code
> >disappears after a few runs.
>
> >I'm wondering how I can get around this problem.
>
> >-Dan
>
> >On Feb 14, 11:27 am, "Norman Yuan" <NotR***@NotReal.not> wrote:
> >> "...Data Source=" & AppBase & ";Jet OLEDB:Engine..."
>
> >> Assume AppBase is declared as String and holds a valid content.
>
> >> "pooba53" <poob***@gmail.com> wrote in message
>
> >>news:1171473240.219144.3100@h3g2000cwc.googlegroups.com...
>
> >> > Take a gander:
>
> >> > Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global
> >> > Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
> >> >        "ocking Mode=1;Data Source=""AppBase"";Jet OLEDB:Engine
> >> > Type=5;Provider=""Mic" & _
> >> >        "rosoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet
> >> > OLEDB:SFP=False;persist sec" & _
> >> >        "urity info=False;Extended Properties=;Mode=Share Deny
> >> > None;Jet OLEDB:Encrypt Dat" & _
> >> >        "abase=False;Jet OLEDB:Create System Database=False;Jet
> >> > OLEDB:Don't Copy Locale o" & _
> >> >        "n Compact=False;Jet OLEDB:Compact Without Replica
> >> > Repair=False;User ID=Admin;Jet" & _
> >> >        " OLEDB:Global Bulk Transactions=1"
>
> >> > I would like to use a string contained in a variable for the Data
> >> > Source in the above example. In the above example the variable is
> >> > called "AppBase". No matter what I do with regard to quotes, no
> >> > quotes, single quotes, etc. the value of the string is never
> >> > substituted in. It remains "AppBase".
>
> >> > Is there some syntax that will allow me to use the contents of a
> >> > variable in my connection string?
>
> >> > Thanks.
>
> Never make changes to the Application generated code.  Make your changes after
> the InitializeComponent() call in the Form's constructor.  Doing so will
> override any settings created or set in the InitiailzeComponent method.
>
> Good luck with your project,
>
> Otis Mukinfus
>
> http://www.otismukinfus.comhttp://www.arltex.comhttp://www.tomchilders.comhttp://www.n5ge.com

My connection string is set up when InitializeComponents() completes.
I understand this, but won't I screw something up if I declare an
additional connection string somewhere else in the code?

Thanks.
-Dan
Author
15 Feb 2007 4:27 PM
W.G. Ryan [MVP]
Pooba:

Have you considered using a ConnectionStringBuilder?  Probably your best bet
for something like this:
http://msdn2.microsoft.com/en-us/library/ms254947.aspx
Show quote
"pooba53" <poob***@gmail.com> wrote in message
news:1171473240.219144.3100@h3g2000cwc.googlegroups.com...
> Take a gander:
>
> Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global
> Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
>        "ocking Mode=1;Data Source=""AppBase"";Jet OLEDB:Engine
> Type=5;Provider=""Mic" & _
>        "rosoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet
> OLEDB:SFP=False;persist sec" & _
>        "urity info=False;Extended Properties=;Mode=Share Deny
> None;Jet OLEDB:Encrypt Dat" & _
>        "abase=False;Jet OLEDB:Create System Database=False;Jet
> OLEDB:Don't Copy Locale o" & _
>        "n Compact=False;Jet OLEDB:Compact Without Replica
> Repair=False;User ID=Admin;Jet" & _
>        " OLEDB:Global Bulk Transactions=1"
>
> I would like to use a string contained in a variable for the Data
> Source in the above example. In the above example the variable is
> called "AppBase". No matter what I do with regard to quotes, no
> quotes, single quotes, etc. the value of the string is never
> substituted in. It remains "AppBase".
>
> Is there some syntax that will allow me to use the contents of a
> variable in my connection string?
>
> Thanks.
>
Author
18 Feb 2007 11:35 PM
pooba53
Show quote
On Feb 15, 10:27 am, "W.G. Ryan [MVP]" <WilliamR...@nospam.gmail.com>
wrote:
> Pooba:
>
> Have you considered using a ConnectionStringBuilder?  Probably your best bet
> for something like this:http://msdn2.microsoft.com/en-us/library/ms254947.aspx"pooba53" <poob***@gmail.com> wrote in message
>
> news:1171473240.219144.3100@h3g2000cwc.googlegroups.com...
>
> > Take a gander:
>
> > Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global
> > Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
> >        "ocking Mode=1;Data Source=""AppBase"";Jet OLEDB:Engine
> > Type=5;Provider=""Mic" & _
> >        "rosoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet
> > OLEDB:SFP=False;persist sec" & _
> >        "urity info=False;Extended Properties=;Mode=Share Deny
> > None;Jet OLEDB:Encrypt Dat" & _
> >        "abase=False;Jet OLEDB:Create System Database=False;Jet
> > OLEDB:Don't Copy Locale o" & _
> >        "n Compact=False;Jet OLEDB:Compact Without Replica
> > Repair=False;User ID=Admin;Jet" & _
> >        " OLEDB:Global Bulk Transactions=1"
>
> > I would like to use a string contained in a variable for the Data
> > Source in the above example. In the above example the variable is
> > called "AppBase". No matter what I do with regard to quotes, no
> > quotes, single quotes, etc. the value of the string is never
> > substituted in. It remains "AppBase".
>
> > Is there some syntax that will allow me to use the contents of a
> > variable in my connection string?
>
> > Thanks.

Can you provide an example of how this would be incorporated and where
in my code? I read the information at the URL above, but that does not
really paint a complete picture.

Thanks.
-Dan

AddThis Social Bookmark Button