Click here to Skip to main content
15,899,313 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear,
I am in great tense regarding connectivity problem.here below I try to explain my problem.
#####################################
HTML
<configuration>
  <configsections>
  </configsections>
  <connectionstrings>
    <add name="ConStr" connectionstring="Data Source=(local)\SQLEXPRESS2;Initial Catalog=Accounts;User ID=sa;Password=sa" providername="System.Data.SqlClient" />
  </connectionstrings>
  <appsettings>
    <add key="ConStr" value="Data Source=(local)\SQLEXPRESS2;Integrated Security=SSPI;Initial Catalog=Accounts;User ID=sa;Password=sa" />
    <add key="SecurityKey" value="My_Encript_Key" />
    <!-- SQL Server connection string -->
    <add key="Conn" value="Data Source=(local)\SQLEXPRESS2;Initial Catalog=master;Integrated Security=SSPI;User ID=sa;Password=sa" />
    <add key="DateStampBackupFiles" value="True" />
    <add key="servername" value="(local)\sqlexpress2" />
    <add key="databasename" value="Accounts" />
    <add key="username" value="sa" />
    <add key="password" value="sa" />
  </appsettings>
  <databaseinformation name="data" username="sa" password="sa" servername="(local)\sqlexpress2" pvdr="SQLOLEB.1" databasename="Accounts" />
</configuration>


here two problems arise I have accessed connection like:
System.Configuration.ConfigurationSettings.AppSettings["ConStr"].ToString();


give error not found ConStr but when i remove
<databaseinformation name="data" username="sa" password="sa" servername="(local)\sqlexpress2" pvdr="SQLOLEB.1" databasename="Accounts"/>

this works fine
I need both work concurrently because I am using
XML
<add key="ConStr" value="Data Source=(local)\SQLEXPRESS2;Integrated Security=SSPI;Initial Catalog=Accounts;User ID=sa;Password=sa" />
    <add key="SecurityKey" value="My_Encript_Key"/>
    <!-- SQL Server connection string -->
    <add key="Conn" value="Data Source=(local)\SQLEXPRESS2;Initial Catalog=master;Integrated Security=SSPI;User ID=sa;Password=sa"/>

for data insert,delete other database works,but
<pre>&lt;databaseinformation name="data" username="sa" password="sa" servername="(local)\sqlexpress2" pvdr="SQLOLEB.1" databasename="Accounts"/&gt;</pre>

this one for crystal report
I am in deep fix,please some one help me to get out this problem
I will be really grateful
Thanks
Mahmud(SN. Software Engineer)
Posted

Hi,

Instead of this line
System.Configuration.ConfigurationSettings.AppSettings["ConStr"].ToString();

use this one:

strConn=ConfigurationManager.ConnectionStrings["ConnectionStringName"].ConnectionString;

objSQLConn=new sqlconnection(strConn);


Note:

Here,strConn-->string variable to get connection string from web.config
 
Share this answer
 
Comments
Mahmudunnabi 24-Nov-11 1:39am    
this one already tried not work same result.
hi,

Instead of use of this line
System.Configuration.ConfigurationSettings.AppSettings["ConStr"].ToString();

use following

System.Configuration.ConfigurationManeger.AppSettings["ConStr"].ToString();
 
Share this answer
 
Comments
Mahmudunnabi 24-Nov-11 0:34am    
System.Configuration.ConfigurationSettings.AppSettings["ConStr"].ToString(); this one I have tried before same problem Configuration system failed to initialize

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