Access Connection Issue In VB.Net
-
Hi Guys, I am trying to use the following connection string, - dcon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Application.StartupPath & "\Database\XYZ.mdb" Application.StartupPath provides the path to the bin folder. However, the Access Databases which I am using are in the Database folder. How should I modify the connectionstring to go one step back from the BIN folder and into the DATABASE folder. Thnx for any help. With Best Regards, Mayur
-
Hi Guys, I am trying to use the following connection string, - dcon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Application.StartupPath & "\Database\XYZ.mdb" Application.StartupPath provides the path to the bin folder. However, the Access Databases which I am using are in the Database folder. How should I modify the connectionstring to go one step back from the BIN folder and into the DATABASE folder. Thnx for any help. With Best Regards, Mayur
Hey, I just figured out how to do it. dcon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Application.StartupPath & "\..\Database\XYZ.mdb However, can anyone tell me how do you set this connection in some common module and use it throughout the application rather than making the connection in every windows form. thnx for any help. With Best Regards, Mayur
-
Hey, I just figured out how to do it. dcon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Application.StartupPath & "\..\Database\XYZ.mdb However, can anyone tell me how do you set this connection in some common module and use it throughout the application rather than making the connection in every windows form. thnx for any help. With Best Regards, Mayur
aap.config You have to "add new item" for this. Specify the connectionstring there. Example:
<configuration> <appSettings> <add key="Provider" value="MSDAORA" /> <add key="DataSource" value="DBTest" /> <add key="UserID" value="Lavanya" /> <add key="Password" value="Password" /> <add key="MailServer" value="EXCH.XYZ.COM"/> </appSettings> </configuration>
or<connectionStrings> <add name="ClaimEZ.My.MySettings.BACFConnection" connectionString="Data Source=MYSERVER;Initial Catalog=MYDB;Integrated Security=True" providerName="System.Data.SqlClient" /> <add name="MyDataLayer.My.MySettings.BACFConnection" connectionString="Data Source=MYSERVER;Initial Catalog=MYDB;Integrated Security=True" providerName="System.Data.SqlClient" /> </connectionStrings>
PraVeeN NinethSense.com/blog/ -
Hey, I just figured out how to do it. dcon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Application.StartupPath & "\..\Database\XYZ.mdb However, can anyone tell me how do you set this connection in some common module and use it throughout the application rather than making the connection in every windows form. thnx for any help. With Best Regards, Mayur
You don't! Best practice to make the connection to the database only when you need to run a query or modify the tables. The rule of thumb is Connect late, Query fast, Disconnect early. You just don't maintain an open connection to the database for the life of a form or, worse yet, and entire application. With an Access database, maintaining an open connection isn't so bad. But on a real SQL server, that is a VERY expensive connection license you hanging onto and not using. Get into the habit... RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome