• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5436
  • Last Modified:

String reference not set to an instance of a String

I have this application here and when i click on a link on one page it should load a crystal report.Following is the error i am getting. After this error i have also pasted the code i am executing.

Server Error in '/appName' Application.
--------------------------------------------------------------------------------

String reference not set to an instance of a String. Parameter name: s
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.ArgumentNullException: String reference not set to an instance of a String. Parameter name: s

Source Error:


Line 77:
Line 78:             public void ConfigureReportConnection(CrystalDecisions.CrystalReports.Engine.ReportDocument crReportDoc)
Line 79:             {
Line 80:                   try
Line 81:                   {
 

Source File: c:\appName_24oct2005\appName\report.cs    Line: 79

Stack Trace:


[ArgumentNullException: String reference not set to an instance of a String.
Parameter name: s]
   System.Text.UnicodeEncoding.GetBytes(String s) +112
   CrystalDecisions.Shared..(String
})
   CrystalDecisions.Shared..q(String
k)
   CrystalDecisions.Shared.ConnectionInfo.set_Password(String value)
   AppNameLib.Report.ConfigureReportConnection(ReportDocument crReportDoc) in c:\appName_24oct2005\AppNamelib\report.cs:79
   AppNameWeb.Reports.Reports.ReportViewer.BindViewer() in c:\appName_24oct2005\AppNameweb\reports\report\reportviewer.aspx.cs:72
   AppNameWeb.Reports.Reports.ReportViewer.Page_Load(Object sender, EventArgs e) in c:\appName_24oct2005\AppNameweb\reports\report\reportviewer.aspx.cs:32
   System.Web.UI.Control.OnLoad(EventArgs e)
   System.Web.UI.Control.LoadRecursive()
   System.Web.UI.Page.ProcessRequestMain()


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET Version:1.1.4322.2032





using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using appName_appNameLib;
using AIDATALib;
using AIutils;
using System.Configuration;

namespace appName_appNameWeb.Reports.Reports
{
      /// <summary>
      /// Summary description for ExportAuditReportViewer.
      /// </summary>
      public class ReportViewer : System.Web.UI.Page
      {
            protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1;
            protected System.Web.UI.WebControls.ImageButton btnPdf;
            CrystalDecisions.CrystalReports.Engine.ReportDocument doc = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

      
            private void Page_Load(object sender, System.EventArgs e)
            {
                  // Put user code to initialize the page here
                  BindViewer();
            }

            private void BindViewer()
            {
                  string strService, strUsername, strPassword;
                  string [] userpass = ConfigurationSettings.AppSettings["rptUserPass"].Split('/');
                  /*                  strService = userpass[0].ToString();
                                    strUsername = userpass[1].ToString();
                                    strPassword = userpass[2].ToString();
                                    */

                  string rptNo= Request.QueryString["Rpt"];
                  string rptFileName= "";
                  switch(rptNo)
                  {
                        case "1":
                              rptFileName = "rptDisplayAllRecords.rpt";
                              break;
                        case "2":
                              rptFileName = "rptDisplayBadRecords.rpt";
                              break;
                        case "3":
                              rptFileName = "rptDisplayGoodRecords.rpt";
                              break;
                        default:
                              Response.Write ("No report is selected");
                              break;
                  }
                  doc.Load(Server.MapPath(".")+ "/" + rptFileName);
                  foreach(string var in Request.QueryString)
                  {
                        if (var != "Rpt")
                        {
                              doc.SetParameterValue(var,Request.QueryString[var]);                              
                        }
                        
                  }

                  appName_appNameLib.Report rptdoc = new appName_appNameLib.Report();
                  rptdoc.ConfigureReportConnection(doc);

                  #region comments on 08Oct2005
                  //                  doc.SetDatabaseLogon(strUsername,strPassword);
                  //                  
                  //                  CrystalDecisions.Shared.TableLogOnInfo crtableLogoninfo = new CrystalDecisions.Shared.TableLogOnInfo();
                  //                  CrystalDecisions.Shared.ConnectionInfo crConnectionInfo = new CrystalDecisions.Shared.ConnectionInfo();
                  //                  CrystalDecisions.CrystalReports.Engine.Tables CrTables;  
                  //                  CrystalDecisions.CrystalReports.Engine.Table CrTable;  
                  //
                  //                  crConnectionInfo.DatabaseName = strService;
                  //                  crConnectionInfo.UserID =strUsername;
                  //                  crConnectionInfo.Password = strPassword;
                  //                  CrTables = doc.Database.Tables;
                  //                  
                  //                  if ( CrTables.Count > 0 )
                  //                  {
                  //                        CrTable = ( CrystalDecisions.CrystalReports.Engine.Table )CrTables[0];
                  //                        //CrTable = ( CrystalDecisions.CrystalReports.Engine.Table )CrTables.Current;
                  //                        while ( CrTables.MoveNext() )
                  //                        {
                  //                              CrTable = ( CrystalDecisions.CrystalReports.Engine.Table )CrTables[0];
                  //                              //CrTable = ( CrystalDecisions.CrystalReports.Engine.Table )CrTables.Current;
                  //                              crtableLogoninfo = CrTable.LogOnInfo;
                  //                              crtableLogoninfo.ConnectionInfo = crConnectionInfo;
                  //                              CrTable.ApplyLogOnInfo(crtableLogoninfo);
                  //                        }
                  //                  }
                  #endregion

                  

                  //                  DataSet  ds =  new DataSet();
                  //                  appName_appNameLib.Import  vRead = new appName_appNameLib.Import(ConfigurationSettings.AppSettings["ConnectionString"]);
                  //                  ds = vRead.Get_Test_Data();
                  //                  WriteSchemaWithXmlTextWriter(ds);
                  //      doc.SetDatabaseLogon(strUsername, strPassword);

                  CrystalReportViewer1.ReportSource =doc;

            }

            #region Web Form Designer generated code
            override protected void OnInit(EventArgs e)
            {
                  //
                  // CODEGEN: This call is required by the ASP.NET Web Form Designer.
                  //
                  InitializeComponent();
                  base.OnInit(e);
            }
            
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {    
                  this.btnPdf.Click += new System.Web.UI.ImageClickEventHandler(this.btnPdf_Click);
                  this.Load += new System.EventHandler(this.Page_Load);

            }
            #endregion

            private void btnPdf_Click(object sender, System.Web.UI.ImageClickEventArgs e)
            {
                  string strPath;
                  string strFileName;
                  strFileName = Session.SessionID.ToString();
                  strPath = Server.MapPath(".") + "/"+ strFileName +".pdf";
                  CrystalDecisions.Shared.DiskFileDestinationOptions DiskOpts = new CrystalDecisions.Shared.DiskFileDestinationOptions();
                  doc.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
                  doc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
                  DiskOpts.DiskFileName = strPath;
                  doc.ExportOptions.DestinationOptions = DiskOpts;
                  doc.Export();
                  //Response.Redirect ("Export/"+ strFileName+".pdf");
                  string str=""+ strFileName+".pdf";
                  Response.Write("<script type='text/javascript'>" +      
                        "open_win=window.open('" + str +
                        "','','top=50,left=50,toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, width=900, height=600');open_win.focus()" +
                        "</script>");
            }

            private void WriteSchemaWithXmlTextWriter(DataSet thisDataSet)
            {
                  // Set the file path and name. Modify this for your purposes.
                  string filename="XSDTest.xsd";
                  // Create a FileStream object with the file path and name.
                  System.IO.FileStream myFileStream = new System.IO.FileStream
                        (filename,System.IO.FileMode.Create);
                  // Create a new XmlTextWriter object with the FileStream.
                  System.Xml.XmlTextWriter MyXmlTextWriter =
                        new System.Xml.XmlTextWriter(myFileStream, System.Text.Encoding.Unicode);
                  // Write the schema into the DataSet and close the reader.
                  thisDataSet.WriteXmlSchema(MyXmlTextWriter );
                  MyXmlTextWriter.Close();
            }
      }
}



rptdoc.ConfigureReportConnection(doc); in the above code calls the following code from where the error occurs.


using System;
using System.Data;
using System.Data.OracleClient;
using System.Configuration;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using AIDATALib;

namespace appName_appNameLib
{
      /// <summary>
      /// Summary description for Report.
      /// </summary>
      public class Report : COracle
      {
            private string DBServerName;
            private string DBUserId;
            private string DBPassword;
            public Report()
            {
                  //
                  // TODO: Add constructor logic here
                  //
                  DatabaseInfo();
            }
            public Report(string ConnectionString) : base(ConnectionString)
            {
                  DatabaseInfo();
            }

            public DataSet Rpt_Multipal_employee()
            {
                  try
                  {
                        //Generating parameters
                        OracleParameter[] para = new OracleParameter[1];
                        // Creating output parameter
                        para[0] = new OracleParameter("CUR_RET", OracleType.Cursor);
                        para[0].Direction =  ParameteappNamerection.Output;                  
                        return RunQuery("appName_appName.RPT_MULTIPAL_EMPLOYEE", para);                  }
                  catch (Exception ex)
                  {
                        throw ex;
                  }
            }
            private void DatabaseInfo()
            {
                  try
                  {
                        string sAccountInfo = ConfigurationSettings.AppSettings["ConnectionString"];

                        // Parse the account info string
                        string [] sArrAccount = sAccountInfo.Split((";=").ToCharArray());
                  
                        for(int i = 0; i < sArrAccount.Length; i++)
                        {
                              if (sArrAccount[i].ToUpper() == "DATA SOURCE")
                              {
                                    DBServerName = sArrAccount[i+1];
                              }
                              else if(sArrAccount[i].ToUpper() == "USER ID")
                              {
                                    DBUserId = sArrAccount[i+1];
                              }
                              else if(sArrAccount[i].ToUpper() == "PASSWORD")
                              {
                                    DBPassword = sArrAccount[i+1];
                              }
                        }
                  }
                  catch (Exception ex)
                  {
                        throw ex;
                  }
            }


            public void ConfigureReportConnection(CrystalDecisions.CrystalReports.Engine.ReportDocument crReportDoc)
            {
                  try
                  {
                        ConnectionInfo crConnectionInfo = new ConnectionInfo();
                        TableLogOnInfo crTableLogOnInfo;
                        Database crDataBase;
                        Tables crTables;
                        CrystalDecisions.CrystalReports.Engine.Table crTable;
                  
                        crConnectionInfo.ServerName = DBServerName;
                        crConnectionInfo.DatabaseName = "";
                        crConnectionInfo.UserID            =  DBUserId;
                        crConnectionInfo.Password      =  DBPassword;
                  
                        crDataBase = crReportDoc.Database;
                        crTables = crDataBase.Tables;
                        for (int i = 0; i < crDataBase.Tables.Count; i++)
                        {
                              crTable = crTables[i];
                              crTableLogOnInfo = crTable.LogOnInfo;
                              crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
                              crTable.ApplyLogOnInfo(crTableLogOnInfo);
                        }
                  }
                  catch (Exception ex)
                  {
                        throw ex;
                  }
            }
      }
}


0
parveenmehta
Asked:
parveenmehta
1 Solution
 
CaldNTCommented:
Where is doc initialized in BindViewer() (or in the class)? I can't find it.


When you invoke:
 doc.Load(Server.MapPath(".")+ "/" + rptFileName);

if in the preceding switch rptNo does not match you invoke doc.Load with rptFileName as "", which does not seem right. You probably want to exit the method before that.

0
 
parveenmehtaAuthor Commented:
Thanks for your reply CaldNT.
Actually i was writting  logic to read the base64string in the code and some where it was reading the same 6 character string instead first converting to a proper connection string.
So my problem is solved now.
But very thank you so much for your help.
0
 
DarthModCommented:
PAQed with points refunded (500)

DarthMod
Community Support Moderator
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now