Click here to Skip to main content
15,942,847 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have published my web application in IIS. when user run the application from browser then it shows the following error. I restart the IIS and the problem solved. But after ten(10) minutes the same error arises again. Please give me a solution.

Server Error in '/erp' Application.
The ConnectionString property has not been initialized.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: The ConnectionString property has not been initialized.

Source Error: 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 

[InvalidOperationException: The ConnectionString property has not been initialized.]
   System.Data.SqlClient.SqlConnection.PermissionDemand() +6316916
   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +6296606
   System.Data.SqlClient.SqlConnection.Open() +300
   BLL.get_InformationdataTable(String sqlstatement) +85
   Smt_Login.Page_Load(Object sender, EventArgs e) +380
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
   System.Web.UI.Control.LoadRecursive() +71
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3048


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1


UPDATE: From Comments:

C#
private static SqlConnection _HRCon;= null;
public static SqlConnection HRCon
{
  get
    {
        if (_HRCon == null)
        {

          _HRCon = new SqlConnection(String.Format("Data Source=SERVER;Initial Catalog=HR;Persist Security Info=True;User ID=sa;Password=123;Connection Timeout=100"));

        }
        return _HRCon;
    }
}
Posted
Updated 26-Aug-15 1:09am
v4
Comments
Andy Lanng 26-Aug-15 6:21am    
Post the code that errors.
I think it should be in here: BLL.get_InformationdataTable(String sqlstatement) +85
Don't forget to tell us what line is +85. We won't see the line numbers when you post it ^_^
Sumon562 26-Aug-15 6:40am    
When I remove directory from IIS and publish it again then it works properly.
Can you explain why it happens, Please?
Andy Lanng 26-Aug-15 6:46am    
I have no idea. Sounds like there may have been an issue with the web.config? maybe the connection string is also being set elsewhere? I couldn't tell without examining your site :/
F-ES Sitecore 26-Aug-15 6:22am    
The solution is to initialise the connection string property. If you want something more specific that relates to your code you'll need to post the relevant code.
aarif moh shaikh 26-Aug-15 6:26am    
Please show your code

1 solution

The right way to call connectionstring is from Web.config. Either using appSetting section or in ConnectionString section
e.g:
in web.config:

XML
<appSettings>
<add key="myConnectionString" value="server=localhost;database=myDb;uid=myUser;password=myPass;" />
</appSettings>

XML
<connectionStrings>
<add name="myConnectionString" connectionString="server=localhost;database=myDb;uid=myUser;password=myPass;" />
</connectionStrings

on page:
C#
String ConnStr= "";
ConnStr= System.Configuration.ConfigurationManager.AppSettings[key];
conn = new SqlConnection(ConnStr)

C#
con = new SqlConnection();
con.ConnectionString =ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;

After these changes if you still get the same issue then please write here, will try to figure that out.
Thanks
 
Share this answer
 
v3

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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