locked
Connection String RRS feed

  • Question

  • I am using Visual Basic 2010 with an Access database.

    When setting up the DataSource I was given the option of including the database in the project,  I have several DataGridView controls in my project and they work perfectly.

    Throughout the remainder of the project I have a number of procedures insert and update as example) and I am not sure if I should use the connection string  created when I set up the DataSource or if I should use the Connection String pointing to my Access file. It seeems to me that using the connection string created when the data sourcs  was created dould be more effective.

    Any suggestions?


    sirmilt

    Saturday, June 16, 2012 7:40 PM

Answers

  • Hi,

    use Application config file, where you put a connection string.

    Then use ConfigurationManager class, to create a simple variable to use for specifiny the connection string inside OleDbConnection provider.


    Mitja

    • Proposed as answer by ThankfulHeart Sunday, June 17, 2012 1:06 AM
    • Marked as answer by Chester Hong Monday, June 25, 2012 2:11 AM
    Saturday, June 16, 2012 7:52 PM

All replies

  • Hi,

    use Application config file, where you put a connection string.

    Then use ConfigurationManager class, to create a simple variable to use for specifiny the connection string inside OleDbConnection provider.


    Mitja

    • Proposed as answer by ThankfulHeart Sunday, June 17, 2012 1:06 AM
    • Marked as answer by Chester Hong Monday, June 25, 2012 2:11 AM
    Saturday, June 16, 2012 7:52 PM
  • Agree with Mijta:-)

    An easy way is that your access file can be published with the same position where your exe file is,then you can just say your conn str like this in the constructor of some initialzing……

    public class Form1:Form
    {
       …………
       public Form1()
       {
           InitializeComponent();
           //Do to connect to the db
           string connStr = Application.StartupPath;
           if(!connStr.EndWith("\"))
           {
              connStr+="\";
           }
           //Then you can use the connStr+your db name nested into your conn str
       }
    }

       QQ我:讨论(Talk)
    下载MSDN桌面工具(Vista,Win7)
    我的博客园
    慈善点击,点击此处

    Sunday, June 17, 2012 1:06 AM