Dynamicaly DB password in connection string

Last post 07-05-2009 11:22 PM by mudassarkhan. 6 replies.

Sort Posts:

  • Dynamicaly DB password in connection string

    07-04-2009, 3:05 AM
    • Member
      8 point Member
    • alcaps
    • Member since 12-20-2008, 3:33 AM
    • Posts 25

    Hi,

    To access my system, the user must enter a password. This pass must be the same of my MS Access DB.

    The system must try use the DB with the entered password. If sucessful, show informations. Else, show a message "wrong password".

    I'm using Dataset, then I must manipulate the connection string. But how????

     

    Like this:

    String ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\database.mdb;Persist Security Info=True;Jet OLEDB:Database Password=" + passwordTextBox.text

    How can I can use this conection string?

     

    Tks,

    Patrick Coelho - www.criapix.com.br

  • Re: Dynamicaly DB password in connection string

    07-04-2009, 8:14 AM

    Not sure what you mean by "how can I use this connection string".  It's just a string that's created dynamically.  Although I am not sure why you are authenticating users at the database connection level.  Can't you just use From Authentication at the application level?


    Regards Mike
    [MVP - ASP/ASP.NET]
    My site
  • Re: Dynamicaly DB password in connection string

    07-04-2009, 11:40 PM
    • Member
      8 point Member
    • alcaps
    • Member since 12-20-2008, 3:33 AM
    • Posts 25

    I want hide the database password and limit the system access.

    Authentication at the application level can expose my MDB password.

    I want use my dynamically created string in a dataset but it only get from web.config. I want override this web.config string.

  • Re: Dynamicaly DB password in connection string

    07-04-2009, 11:53 PM
    Answer
    • All-Star
      57,544 point All-Star
    • mudassarkhan
    • Member since 02-28-2008, 10:28 AM
    • Mumbai, India
    • Posts 10,195

     You can do something like this Place the placeholders

    <add name ="Excel03ConString"

           connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};

                             Extended Properties='Excel 8.0;HDR={1}'"/>

     

    And in front end then do String.Format to fill them

    string conStr = ConfigurationManager.ConnectionStrings["Excel03ConString"] .ConnectionString;

    conStr = String.Format(conStr, "C:\\Book1.xls", "yes");

     

     

    MAK [MVP ASP/ASP.Net]

    ASP.Net Consultant My Site : ASPSnippets

    Delete mutiple rows in GridView

    Using AsyncFileUpload Control
  • Re: Dynamicaly DB password in connection string

    07-05-2009, 2:08 AM
    Answer

    alcaps:
    I want hide the database password and limit the system access.

    You can encrypt the connection string (together with the password) in your web.config file: http://www.google.co.uk/search?hl=en&q=web+config+encrypt+connection+string&btnG=Google+Search&meta=&aq=2&oq=web+config+encr

    If you are really concerned about security, you should not be using Access.  There are plenty of tools available for cracking open password protected databases.  If you believe someone can get access to your code or web.config, then it stands to reason that they can get your database and force it open.


    Regards Mike
    [MVP - ASP/ASP.NET]
    My site
  • Re: Dynamicaly DB password in connection string

    07-05-2009, 11:05 PM
    • Member
      8 point Member
    • alcaps
    • Member since 12-20-2008, 3:33 AM
    • Posts 25

    Hi,

    I have in web.config:
    <add name="controleConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\controle.mdb;Persist Security Info=True;Jet OLEDB:Database Password={0}" providerName="System.Data.OleDb"/>

    In code now I have:
    string conStr = ConfigurationManager.ConnectionStrings["controleConnectionString"].ConnectionString;
    conStr = String.Format(conStr, "password");

    This code only create a connection string. How I use this in a dataset?

    I tryed:
    ConfigurationManager.ConnectionStrings["controleConnectionString"].ConnectionString = conStr

    But I get a error "Configuration read-only".

     

    Tks

  • Re: Dynamicaly DB password in connection string

    07-05-2009, 11:22 PM
    • All-Star
      57,544 point All-Star
    • mudassarkhan
    • Member since 02-28-2008, 10:28 AM
    • Mumbai, India
    • Posts 10,195

    alcaps:

    I tryed:
    ConfigurationManager.ConnectionStrings["controleConnectionString"].ConnectionString = conStr

    But I get a error "Configuration read-only".

     

    Why you want to reset the connection string in web.config

    This variable conStr has the connection string in it use this to connect to database

    MAK [MVP ASP/ASP.Net]

    ASP.Net Consultant My Site : ASPSnippets

    Delete mutiple rows in GridView

    Using AsyncFileUpload Control
Page 1 of 1 (7 items)