I've created a windows forms application, and it was working fine and then inexplicably started giving an error. It has a user defined control which queries an access database. When I try to load the control into my form with the designer. I get the error:
Failed to create component 'myControl'. The error message follows: 'System.data.OleDbException: Could not find file F:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\Data.mdb' at ...
This confuses me because 1: I never pointed anything to this location. My database file was copied automatically into the application directory and output folder, so shouldn't it look for it there? The connection string looks like: <add name="TestTask1.My.MySettings.DataConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Data.mdb" providerName="System.Data.OleDb" /> I've tried outputting the datadirectory, but it returns nothing. 2. The application finds the data when previewed from the datasource so it seems like it should work. 3. The control originally loaded fine, but later started giving me a different error about not recognizing the control, and I don't know why. So I deleted the control and tried to re-add it and it gave this error.
Can someone please explain what could be going on? Can I tell the project to look in its own directory for the database file? Thanks
Seems the |DataDirectory| doesn’t point to the right place. To set the DataDirectory property, call the AppDomain.SetData method. Or change the datasouce to the correct database path.
A related thread: http://social.msdn.microsoft.com/Forums/en-US/sqlce/thread/0712dd47-8437-4c84-b27e-2b12fddf2153/
Best regards, Ling Wang
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.