|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Using a Variable within a Connection StringMe.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. "...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. > 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.
Show quote
On 14 Feb 2007 10:53:42 -0800, "pooba53" <poob***@gmail.com> wrote: Never make changes to the Application generated code. Make your changes after>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. > 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 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: My connection string is set up when InitializeComponents() completes.> > > > >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 I understand this, but won't I screw something up if I declare an additional connection string somewhere else in the code? Thanks. -Dan 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. >
Show quote
On Feb 15, 10:27 am, "W.G. Ryan [MVP]" <WilliamR...@nospam.gmail.com> Can you provide an example of how this would be incorporated and wherewrote: > 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. in my code? I read the information at the URL above, but that does not really paint a complete picture. Thanks. -Dan |
|||||||||||||||||||||||