Results 1 to 3 of 3

Thread: Obselete COnnection String

  1. #1

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Obselete COnnection String

    hello guyz!! currently, i have this code(C# 2005) below to connect to my SQL 2005 Express edition

    Code:
    Code:
    string sqlConnStr;
    sqlConnStr = System.Configuration.COnfigurationSettings.AppSettings["ConnectionString"];
    SqlConnection sqlConn = new SqlConnection(sqlConnStr);
    slqConn.Open
    App.COnfig (excerpt)
    Code:
    <appSettings>
            <add key="ConnectionString" value="Data SOurce =....." />
    </appSettings>
    But it seems that the Method is obselete and according to Visual Studio 2005 it has been replaced by System.Configuration! System.Configuration.COnfigurationManager.AppSetting'. My question is how can i enhance it? thanks in advance!!!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Obselete COnnection String

    The config file and its handling has been beefed up in VS 2005. You should create your connection string on the Settings tab of the project properties. You can create it as type String and just type in the value or you can create it as type ConnectionString and create it by point and click. Either way, assuming that you create a setting named MyConnectionString you would retrieve it in code like so:
    Code:
    SqlConnection con = new SqlConnection(Properties.Settings.Default.MyConnectionString);
    If you create your connection in the designer you can bind the ConnectionString property to the setting in the ApplicationSettings section of the Properties window. In fact, you can even create the setting from there.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Re: Obselete COnnection String

    Thanks a lot...it really helps me..Thanks for the info. again!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width