web.config sql connectionstring problem

  • Thread starter Thread starter SSP
  • Start date Start date
S

SSP

Dear .Netters,

Following is the code from my web.config file
==========
<add key="SqlConnectionA.ConnectionString" value="workstation id=myPC;packet
size=4096;integrated security=SSPI;data source=\"myPC\\myDB\";persist
security info=False;initial catalog=telecomTimeSheet" />
==========

I call this connectionstring in my code behind file like this:
============
this.sqlConnection1.ConnectionString =
System.Configuration.ConfigurationSettings.AppSettings.GetValues("SqlConnect
ionA.ConnectionString").ToString();
=============

When I view the file I get the following error:

=========
[ArgumentException: Format of the initialization string does not conform to
specification starting at index 0.]
System.Data.Common.DBConnectionString.GetKeyValuePair(Char[]
connectionString, Int32 currentPosition, String& key, Char[] valuebuf,
Int32& vallength, Boolean& isempty) +942
System.Data.Common.DBConnectionString.ParseInternal(Char[]
connectionString, UdlSupport checkForUdl, NameValuePair& keychain) +116
System.Data.Common.DBConnectionString..ctor(String connectionString,
UdlSupport checkForUdl) +114
System.Data.SqlClient.SqlConnectionString..ctor(String connectionString)
+13
System.Data.SqlClient.SqlConnectionString.ParseString(String
connectionString) +96
System.Data.SqlClient.SqlConnection.set_ConnectionString(String value)
+11
ttsheet.timesheet.timeSheetForm.InitializeComponent() +1590
ttsheet.timesheet.timeSheetForm.OnInit(EventArgs e) +13
System.Web.UI.Control.InitRecursive(Control namingContainer) +241
System.Web.UI.Control.InitRecursive(Control namingContainer) +179
System.Web.UI.Control.InitRecursive(Control namingContainer) +179
System.Web.UI.Page.ProcessRequestMain() +174
=========

Any ideas in what I am doing wrong?

SSP
 
Drop the GetValues part, just use:

System.Configuration.ConfigurationSettings.AppSettings("SqlConnectionA.Conne
ctionString")

Hope it helps...
 
Back
Top