public SqlConnection GetConnection() { string cConnection = ConfigurationSettings.AppSettings["ConnectionString"]; if (cConnection == null) { cConnection = "server=(local);database=localdatabase;uid=sa;pwd="; } SqlConnection conn = new SqlConnection(cConnection); return conn; }Note that I have a default connection string set to get a local database if it doesn't find the ConnectionString in the config file. You don't have to do this the same way, you could produce an error or something instead, it's up to you. Again, as I mentioned in my previous post, this is not very secure as the password is in plain view. If you used trusted connection instead of username/password, then I guess it wouldn't matter.
>><?xml version="1.0" standalone="yes"?> >><configuration> >> <appSettings> >> <add key="ConnectionString" value="server=MyServer;database=MyDataBase;uid=UserName;pwd=MyPassword" /> >> </appSettings> >></configuration> >>>>Not real secure, as the password is in plain view, but I'll let you figure out how to deal with that. <g> If this is on the client machine, then the config file would be called MyApp.exe.config and would reside with the EXE. We connect to our database via Web Services, and so in that case the config file is on the Web Server and is called web.config.