Click here to Skip to main content
15,906,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hello guys please help me out i am just struck on this point I have tried many solutions but still no output please help me in this regard...

Connection String code:


XML
<connectionStrings>
   <add name="EM_DataConnectionString" connectionString="Data Source='localhost;User ID='user';Password='pwd';nitial Catalog='EM_Data'"
   providerName="System.Data.SqlClient" />
</connectionStrings>



ASPX.CS code is:

C#
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["UR_DataConnectionString"].ToString());


Error is:

XML
Format of the initialization string does not conform to specification starting at index 0.

Line 17:     protected void btnLogin_Click(object sender, EventArgs e)
Line 18:     {
Line 19:         SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["EM_DataConnectionString"].ConnectionString);


Line 19 comes as invalid please help me why I am getting this error
Posted
Comments
Richard C Bishop 6-Nov-13 17:59pm    
My guess would be to remove the "'" from around your Data Source, ID, Password, and Initial Catalog values. Make sure everything is spelled correctly as well.
Member 10361501 6-Nov-13 18:29pm    
Thank you very much sir to make me realise about my blindness, your suggestion worked for me

You have a typo in your connection string property. In the string below you have nitial Catalog, but it should be Initial Catalog. Also, as Richard C Bishop said, remove the single quotes from inside your connectionString value.
HTML
<connectionstrings>
   <add name="EM_DataConnectionString" connectionstring="Data Source='localhost;User ID='user';Password='pwd';nitial Catalog='EM_Data'">
   providerName="System.Data.SqlClient" />
</add></connectionstrings>

Try this one...
C#
<add name="EM_DataConnectionString" connectionString="Data Source=localhost;User ID=user;Password=pwd;Initial Catalog=EM_Data"
   providerName="System.Data.SqlClient" />
 
Share this answer
 
v3
Comments
Member 10361501 6-Nov-13 18:30pm    
Thank you sir it worked for me
You have a typo in your connection string property. In the string below you have nitial Catalog, but it should be Initial Catalog. Also, as Richard C Bishop said, remove the single quotes from inside your connectionString value.
HTML
<connectionstrings>
   <add name="EM_DataConnectionString" connectionstring="Data Source='localhost;User ID='user';Password='pwd';<b>nitial Catalog</b>='EM_Data'">
   providerName="System.Data.SqlClient" />
</add></connectionstrings>

Try this one...
C#
<connectionstrings>
   <add name="EM_DataConnectionString" connectionstring="Data Source=localhost;User ID=user;Password=pwd;Initial Catalog=EM_Data">
   providerName="System.Data.SqlClient" />
</add></connectionstrings>
 
Share this answer
 
Comments
Member 10361501 6-Nov-13 18:43pm    
thank you sir its worked for me :)
Member 11765235 18-Jun-15 7:26am    
I have the same problem with my connection string
<add key="constring" value=" provider connection string="Data Source=192.240.97.122; Initial Catalog=#####; User ID=######; Password=#####;">
Member 11765235 18-Jun-15 7:28am    
<add key="constring" value=" provider connection string="Data Source=192.240.97.122; Initial Catalog=#####; User ID=######; Password=#####;">

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900