none
Connecting to a .MDF file in C#

    Question

  • I'm trying to connect to a .mdf file for queries and such, but I can't make a connection.  The file is local, and I added it as a data source.

                string conn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=A_File.mdf"; 
                OleDbConnection myConn = new OleDbConnection(); 
                myConn.ConnectionString = conn
                OleDbDataAdapter daScenario = new OleDbDataAdapter("SELECT * FROM Students", myConn); 
                DataSet dsScen = new DataSet(); 
                daScenario.Fill(dsScen); 

    It fails on

    DataSet dsScen = new DataSet();

    I get an OleDBException:

    Unrecognized database format 'C:\Documents and Settings\...\bin\Debug\A_File.mdf'.

    Any way to fix this so I can connect and start making queries/statements?

    Thanks in advance.



    Tuesday, October 14, 2008 2:47 PM

Answers

All replies