Hi,
I'm building a module that needs to read records from a separate table in my DNN database. I've written the following line in my code behind page to call the DNN connection string saved in web.config:
using (System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DNN"].ConnectionString))
The corresponding entry in web.config is as follows:
<add name="DNN" connectionString="DataSource = sqlsrv; InitialCatalog = DNN563; IntegratedSecurity = True" providerName="System.Data.SqlClient"/>
When I run the module in my DNN portal, I receive an error. Event Manager entry is as follows:
Message: DotNetNuke.Services.Exceptions.PageLoadException: Object reference not set to an instance of an object. ---> System.NullReferenceException: Object reference not set to an instance of an object. at DNNSharp.Revindex.ViewInvoices.Page_Load(Object sender, EventArgs e) in C:\inetpub\wwwroot\DNN563\DesktopModules\DNNSharp.Revindex\ViewInvoices.ascx.cs:line 46 at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) --- End of inner exception stack trace ---
Am I using the correct connection string format and referencing it correctly from my code behind? Is the above error being caused by the connection string statement? How do I remedy this?
Thanks,
Sid