none
C# mdf database connection gives error. RRS feed

  • Question

  • Hello there, im trying to connect my local database to my c# project but im getting this error "An OLE DB Provider was not specified in the ConnectionString".

    Here is the code:

    public static string curDir = System.IO.Directory.GetCurrentDirectory();
    OleDbConnection con;
    
            void test()
            {
    con = new OleDbConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=\""+curDir+"\\ABCDSaveDataDB.mdf\";Integrated Security=True");
            }

    I created the database using this tutorial(only exception being i checked the mark at 7:10)
    i don't believe problem is due to this but just to be sure.

    Wednesday, July 3, 2019 11:52 PM

Answers

  • Hi xanrer,

    Thank you for posting here.

    Based on your description, you want to connect database by accessing .mdf file.

    As usual, we need to use Sqlconnection to access the file instead of OlebConnection. The following link could be helpful for you.

    https://stackoverflow.com/questions/8926512/how-do-i-connect-to-an-mdf-database-file

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by xanrer Thursday, July 4, 2019 2:39 AM
    Thursday, July 4, 2019 2:01 AM
    Moderator

All replies

  • Hi xanrer,

    Thank you for posting here.

    Based on your description, you want to connect database by accessing .mdf file.

    As usual, we need to use Sqlconnection to access the file instead of OlebConnection. The following link could be helpful for you.

    https://stackoverflow.com/questions/8926512/how-do-i-connect-to-an-mdf-database-file

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by xanrer Thursday, July 4, 2019 2:39 AM
    Thursday, July 4, 2019 2:01 AM
    Moderator
  • Oh.. Thank you!
    Thursday, July 4, 2019 2:39 AM