none
Problem connecting to an Access database with DBProviderFactory RRS feed

  • Question

  • Hi;

     

    I can't seem to open an Access 2000 database with the following dbprovider factory code :

     

     In my source :

      

    Code Snippet

    Dim dp As String = ConfigurationManager.AppSettings("provider")

    Dim cnStr As String = _

    ConfigurationManager.ConnectionStrings("AFIDConnectionString").ConnectionString

    ' The factory provider

    Dim df As DbProviderFactory = DbProviderFactories.GetFactory(dp)

    ' Now make the connection object

    Dim conn As DbConnection = df.CreateConnection()

     

     

     

    In my App config file I have :

     

     

    Code Snippet

    <configuration>

    <appSettings>

    <add key="provider" value="System.Data.OleDb" />

    </< FONT>appSettings>

    <connectionStrings>

    <add name="AFIDConnectionString"

         connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data       Source=\\wmcrystalt\sysData\FTPFiles\databases\FTPFilesRpts.mdb;" />

    </< FONT>connectionStrings>

     

     

    When I step through the code in my locals windows I notice that

     

    Code Snippet

    -  df {System.Data.OleDb.OleDbFactory} System.Data.Common.DbProviderFactory
    +  System.Data.OleDb.OleDbFactory {System.Data.OleDb.OleDbFactory} System.Data.OleDb.OleDbFactory
      CanCreateDataSourceEnumerator False Boolean

     

     

     

      Can't you connect to an Access database i.e. MDB through the dbProvider object ?

     

      Thanks for any insights,

     

      Gordon

     


     

     

     

     

    Monday, January 28, 2008 4:23 PM

Answers

  •  

     

    I omitted the step highlighted in black.

     

    Code Snippet

    Dim dp As String = ConfigurationManager.AppSettings("provider")

    Dim cnStr As String = _

    ConfigurationManager.ConnectionStrings("AFIDConnectionString").ConnectionString

    ' The factory provider

    Dim df As DbProviderFactory = DbProviderFactories.GetFactory(dp)

    ' Now make the connection object

    Dim conn As DbConnection = df.CreateConnection()

    Dim conn As DbConnection = df.CreateConnection()

    conn.ConnectionString = cnStr

     

     

    Thanks,

     

    GeeMann

    Monday, January 28, 2008 9:05 PM