Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Writing to and Reading from Access Database Problem?
 

Writing to and Reading from Access Database Problem?

I am having a strange issue of being able to write to/read from an access database when I publish my windows app. I can connect to the database because I can create and view reports and view tables creating using the wizard but it will not allow me to read or write to the database when I created my own connection string. I get the following error:

"Unhandled exception has occurred in your application...Could not find file, C:...folder...path"

The connection string I'm using is: "Data Source=" & Application.StartupPath &"\databasename.mdb"

However, if I go check into the Application Files I can see that my .mdb file's publish status is Data File(Auto), which is default, and I switch that to "Include" and then publish again I can write to the database when using my coded connection string. The only problem is that I cannot view tables created from the wizard. I get the same error as before.

My problem is obviously my connection string so my question is how to I change my connection string to match what the wizard is using when it connects to a added data source?

Thanks for your help.
Jason.PK  Tuesday, September 08, 2009 11:49 AM
Hi Jason.PK,

We can use the OleDbConnectionStringBuilder to build a connection string. This is a sample:
http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbconnectionstringbuilder.aspx.

If you want to directly create a connection string, you can follow this document which contains several samples of the connection string:
http://www.connectionstrings.com/access.
For example: Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\directory\demo.mdb;User Id=admin;Password=;

Regards,
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Thursday, September 10, 2009 8:07 AM
Hi Jason.PK,

We can use the OleDbConnectionStringBuilder to build a connection string. This is a sample:
http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbconnectionstringbuilder.aspx.

If you want to directly create a connection string, you can follow this document which contains several samples of the connection string:
http://www.connectionstrings.com/access.
For example: Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\directory\demo.mdb;User Id=admin;Password=;

Regards,
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Thursday, September 10, 2009 8:07 AM

You can use google to search for other answers

Custom Search

More Threads

• How to merge column in DataGridView ?
• Can I tell if the header row in a bound grid is clicked
• data from table one, displayed, selected, and saved to table 2.?
• Databound Combo Box
• DataGridView - Multiple Column Sort
• TreeView: Enable checkboxes but hide checkbox for childnodes.
• Sum column by header name and get average
• DataGridView ComboBox Selected Value Not Retained
• Databinding problem with DataGridView/DataTable - Why is the binding not done immediatly after setting DataGridView.DataSource?
• DataGridViewCell Painting Problem