Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0
Hi friends,
 
I have a problem in MS Access connection string , i am reading Access files , those access files contains password,Each MS Access file contains one passwords from 2 randomnly, so i dont know which will be the password dynamically, so based on the password i want to change the connection string.
any one please guide me.
Posted 17-Sep-12 3:13am
Rockstar_5.7K
Edited 17-Sep-12 3:14am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hey there,
 
Take a look at SqlConnectionStringBuilder[^].
var conStringBuilder = new SqlConnectionStringBuilder
    {
        UserID = @"something",
        Password = @"passphrase",
        DataSource = @".\SQLExpress",
        InitialCatalog = @"MyDatabase"
    };
var connectionString = conStringBuilder.ConnectionString;
I know I've used .Net 4.0 syntax but this class is available from .Net 2.0. So it should help you to change the username password accordingly and generate the desired connection string.
 
Hope this helps, regards
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Imagine your connection string for MS Access would look like this:
 
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=;"
 
Now to make the password interchangeable by code you rewrite it like so:
 
Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};User Id=admin;Password={1};
 
You can then do something like this in your code:
 
String connectionStringPattern = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};User Id=admin;Password={1};";
foreach(currentFileName in listOfAccessFileNames)
{
    String connectionStringPatternWithFile = String.Format(connectionStringPattern, new String[] {currentFileName, "{0}");
    String passWord1 = "firstPassword";
    String passWord2 = "secondPassowrd";
 
    String connectionString1 = String.Format(connectionStringPatternWithFile, passWord1);
    String connectionString2 = String.Format(connectionStringPatternWithFile, passWord2);
 
    // Here place some code where you would try to open a connection to the current Access file 
    // using both variants of the password
}
 
Hope you get the idea!
 
— Manfred
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

the question is not clear.
  Permalink  
Comments
VijayChauhan123 at 17-Sep-12 8:37am
   
MS Access files may contain different passwords, out of 2 passwords, dynamically we have to change the connection string if one gets failed to open , then use another connection string.
Wes Aday at 17-Sep-12 9:05am
   
And this is not a solution
VijayChauhan123 at 20-Sep-12 0:10am
   
can u tell me the correct solution?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Marcin Kozub 295
1 OriginalGriff 273
2 Richard MacCutchan 229
3 Praneet Nadkar 197
4 Sergey Alexandrovich Kryukov 190
0 OriginalGriff 7,913
1 Sergey Alexandrovich Kryukov 7,232
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,865


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 17 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100