Click here to Skip to main content
14,422,139 members
Rate this:
Please Sign up or sign in to vote.
See more: , +
I am creating multi DB application from Access DB's. Using a Open dialog box I need to update the connection string DB file path for the access DB. This does not work and gives the error:
No error message available, result code: DB_SEC_E_AUTH_FAILED(0x80040E4D).

But when I declare a string with the same DB path and add to the connection string it works perfectly. But dose not serve my purpose. Following is the code:

(This Manual Declarations works) But not the DUP1 variable picked from Load form Event.., even though variable is updated with path picked from the other DB.

static string ss = @"C:\Users\hp\Desktop\Master_Database.mdb";

    static string DUP1;
    static string HO1 = "";
    static string MES1 = "";

    static string dup = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DUP1 + ";Jet OLEDB:Database Password=1010101010 ";

       static string sqlcon = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\hp\Documents\Database1.accdb";

    OleDbConnection OleConn = new OleDbConnection(sqlcon);
    OleDbConnection db = new OleDbConnection(dup);
    OleDbConnection dbmes = new OleDbConnection(mes);
    OleDbConnection dbho = new OleDbConnection(HO);

    string SQL = "SELECT* from SalesDetails";

    string sql1 = "SELECT * from SalesHeader";


    private void Form1_Load(object sender, EventArgs e)
    {
        DataTable s = new DataTable();

        OleConn.Open();
        OleDbCommand adc = new OleDbCommand("SELECT* from Filepaths", OleConn);
        OleDbDataAdapter u = new OleDbDataAdapter();
        u.SelectCommand = adc;
        u.Fill(s);
        OleConn.Close();
        DataRow j;
        DataRow x;
        DataRow t;
        j = s.Rows[0];
        x = s.Rows[1];
        t = s.Rows[2];

       DUP1 = j.ItemArray.GetValue(1).ToString();  //C:\Users\hp\Desktop\Master_Database.mdb (same path as Variable "SS")

       HO1 = x.ItemArray.GetValue(1).ToString();
       MES1 = t.ItemArray.GetValue(1).ToString();
But this does not open the DB (Updated DUP1 variable)! What am I doing wrong?
Posted
Comments
Aravindba 22-Apr-14 2:59am
   
for what purpose u try in dynamically change database path ?when developing and deployed in client machine need to change db path ,so only u try ? in which application you create web or windows application ?
Fazlan85 22-Apr-14 3:44am
   
This is stand alone windows application. I want to allow the user to browse the Access DB from a Open dialog and update the file path in the connection string.

Thank you for suggestion. Will try that when i get back. The point to note is when i declare the same path through the "SS" variable connection works perfectly..Is the @ mark important by any means?? I ve tried adding that as well..
Rate this:
Please Sign up or sign in to vote.

Solution 1

Hi Declare this after u get path in DUP1




  DataRow t;
        j = s.Rows[0];
        x = s.Rows[1];
        t = s.Rows[2];
 
       DUP1 = j.ItemArray.GetValue(1).ToString(); 

//here u declare string and create oledbconnection.what u try before u getting valule for DUP1 u try to create oldeconnection

static string dup = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DUP1 + ";Jet OLEDB:Database Password=1010101010 ";
 OleDbConnection db = new OleDbConnection(dup);



Regards
Aravind
   
Comments
Fazlan85 23-Apr-14 8:14am
   
Nopes no luck with Suggestion. Still the same error. The issue is with incorperating the file path obtained via DUP1 variable back into connection string during form load. Where as the manual link created via SS variable works fine with the same path details.
Rate this:
Please Sign up or sign in to vote.

Solution 2

Hi all I solved it.

I did something like this..

private void Form1_Load(object sender, EventArgs e)
  {



<pre>static string dup = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DUP1 + ";Jet OLEDB:Database Password=1010101010 ";



    OleDbConnection db = new OleDbConnection(dup);




and inserted the code into the button which executes the query so the File path gets update at the time executing the query.
   

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




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