none
config file to connect to a SQL Server 2005 database RRS feed

  • Question

  •  

    A friend mentioned using a config file to connect to a database. I am assuming that this would hold the connection string.

     

    Can anyone recommend any examples or other info on the web for this?

     

                                       ...................thanks

    Tuesday, October 16, 2007 12:46 AM

Answers

All replies

  • Thanks for the help. There are a few things that are not covered in detail in the article that I have questions about.

     

    I am assuming that the code like below (from the article) should go in the config file. I am also assuming that this is supposed to be an XML document. I am assuming this because of the opening and closing brackets which aren't used in C# and resemble that of an xml document.

     

    <connectionStrings>
        <add name="EmployeeDB”
          connectionString="DATABASE=…;UID=…;PWD=…;” />
        <add name="OrdersDB”
          connectionString="~\DATA\CustDB.mdb” />
    </connectionStrings></PRE>

     

     The article talks about using this with web.config file. I think this is a file that is native to only asp.net apps. I am trying to use this feature with a console app. Is there a way that this can be done with a console app?  I checked the solution explorer of my app but couldn't find any type of of config file( or anything that seemed similar).

     

    I appreciate the help. Things seem to be getting a little clearer.

     

     

    .............................................thanks

     

    Wednesday, October 17, 2007 8:46 PM
  • For your console application, you will have to add a item of type "Application Configuration File" to your project. This will actually add a 'app.config' file to your project and then you can go ahead and add the sections as you have described in your previous post.

     

    Hope this helps,

     

    Regards,

    Abhisheik.

    Wednesday, October 17, 2007 8:57 PM
  • Everything is correct (but you do not need </PRE> part). All the settings should be stored in .config file of the application. In a case of ASP.NET application name of the file is always web.config. For all other types of applications (console or Windows worms) name of the file is Executablename.config. For example, if your console application is MyApp.exe, then related config file is MyApp.config.

    Thursday, October 18, 2007 10:34 AM
    Moderator