KMBonin KMBonin - 1 year ago 106
ASP.NET (C#) Question

SQL Server ConnectionString Error

Just changed over to a SQL Server database and am trying to access my connectionstring set in my web.config. I am getting the following error:

The ConnectionString property has not been initialized.

Web.Config code:

<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="EditorGenerator.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<add name="loganWebConn" connectionString="Data Source=PMCUSSRV05;Integrated Security=true;Initial Catalog= loganWeb;User Id=logan_sys;Password=appPwd;" providerName="System.Data.SqlClient" />

C# code:

SqlConnection con = new System.Data.SqlClient.SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["loganWebConn"].ConnectionString;
string sql = "select j.*, u.fullname as plannerName from logan_jobs j left join on logan_user u on u.userID = j.plannerID ";
sql += "where 0=0 ";
sql += "and plannerID =" + planner + " ";
sql += "and " + dept + " in (select deptID from logan_prodData p where p.jobID = j.jobID and curEstEndDate >= " + fromDate + " and curEstEndDate <= " + toDate + " ) ";
sql += "order by jobNumber";

SqlCommand cmd = new SqlCommand(sql, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

What am I doing wrong? I know this is really basic stuff here...

Answer Source

I believe that your problem is that you have specified Integrated Security=true, but you have also supplied a username and password.

If you really want to use Integrated Security, remove the username/password

It would also be worthwhile removing the space before the catalog name loganWeb.

This would make your connection string

<add name="loganWebConn" connectionString="Data Source=PMCUSSRV05;Initial Catalog=loganWeb;Integrated Security=true;" providerName="System.Data.SqlClient" />
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download