Search code examples
c#oledboledbconnection

OleDbConnection connection string Data Source error


This is the connection string I am using.

string connection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\CULVERT2.DBF;Extended Properties=dBASE IV;";

The error I am receiving is C:\CULVERT2.DBF' is not a valid path.

Using C# and .NET 4

Why is it not seeing the file?


Solution

  • You may need quotes around the Data Source attribute as well as around the Extended Properties:

    string connection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\"C:\\CULVERT2.DBF\";Extended Properties=\"dBASE IV;\"";
    

    Also, you may want to verify that the file is named exactly as you have it, and that you have permissions to the file ;)

    UPDATE:

    You need to specify only the folder, not the filename as per http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/7a3f7bc0-a5c5-45ee-a488-fc262e795ec6. In your case that would be just C:\