Data Source for mdb connection

  • Thread starter Thread starter esroinc
  • Start date Start date
E

esroinc

Would like to replace Data Source mdb location and name with a string
variable. For example:

where I have

@"Data Source = c:\mydirectory\mydatabase.mdb;" +

the c:\mydirectory\mydatabase.mdb would be replaced with a variable.

Thanks Bob J.
 
Hi,

Would like to replace Data Source mdb location and name with a string
variable. For example:

where I have

@"Data Source = c:\mydirectory\mydatabase.mdb;" +

the c:\mydirectory\mydatabase.mdb would be replaced with a variable.

I do not understand where is the problem, you can have the connection string
split in several string vars and just do like

OleDbConnection c = new OleDbConnection( str1 + str2 );
 
Hello (e-mail address removed),

Maybe u need to use smth like string.Format("Data Source = {0};" , YouString)?!
Would like to replace Data Source mdb location and name with a string
variable. For example:

where I have

@"Data Source = c:\mydirectory\mydatabase.mdb;" +

the c:\mydirectory\mydatabase.mdb would be replaced with a variable.

Thanks Bob J.
---
WBR, Michael Nemtsev [C# MVP].
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
 
Ignacio,

I wish it was that easy. Here is what I'm actually using:

strDBLocation=@"Provider=Microsoft.JET.OLEDB.4.0;Data Source=f:
\Cresi2\MyStuff.mdb;Jet OLEDB:Database Password="+DBPassWord;

If I substitute a variable after Data Source =, the compiler will not
coginize it. The only place where I have been able to substitue a var
is at the end. I have tried to break this down into different strings
and add them to gether, but nothing works.
 
Hi,

Ignacio,

I wish it was that easy. Here is what I'm actually using:

strDBLocation=@"Provider=Microsoft.JET.OLEDB.4.0;Data Source=f:
\Cresi2\MyStuff.mdb;Jet OLEDB:Database Password="+DBPassWord;

string db = @"f:\Cresi2\MyStuff.mdb";

string strDBLocation = "Provider=Microsoft.JET.OLEDB.4.0;Data Source=" + db
+ ;Jet OLEDB:Database Password="+DBPassWord;


That should work.

Ps:
I think that using String.Format improve the readiness:

string strDBLocation = String.Format(
"Provider=Microsoft.JET.OLEDB.4.0;Data Source={0}:Database Password={1}",
DBLocation , DBPassWord );
 
Back
Top