Error 2 'System.Web.HttpApplicationState' does not contain a definition for 'startuppath' and no extension method 'startuppath' accepting a first argument of type 'System.Web.HttpApplicationState' could be found (are you missing a using directive or an assembly reference?) E:\Report1\global\ 77 36 E:\Report1\global\


please help me..
i want to override the connection string of crystal reports which was connected by the database experts..
now i want to override with with new connection string .. the above error is diaplaying..
the following is my code if there is any mistake please correct me...
its urgent please help me....

the code is..

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Data.OleDb;
using CrystalDecisions.Enterprise;


public partial class _Default : System.Web.UI.Page
{
    string connections = ConfigurationManager.ConnectionStrings["SqlConn"].ConnectionString;
    private TableLogOnInfo LogInfo = new TableLogOnInfo();
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

         

          }


    }



    private void SetLogonInfo()
    {
        try
        {
            LogInfo.ConnectionInfo.ServerName = "";
            LogInfo.ConnectionInfo.UserID = "";
            LogInfo.ConnectionInfo.Password = "";
            LogInfo.ConnectionInfo.DatabaseName = "";
        }
        catch (Exception e)
        {
            
        }
    }
    //private void setDBLOGONforREPORT(ConnectionInfo myconnectioninfo)
    //{
    //    TableLogOnInfos mytableloginfos = new TableLogOnInfos();
    //    mytableloginfos = CrystalReportViewer1.LogOnInfo;
    //    foreach (TableLogOnInfo myTableLogOnInfo in mytableloginfos)
    //    {
    //        myTableLogOnInfo.ConnectionInfo = myconnectioninfo;
    //    }

    //}

      protected void btn_emp_Click(object sender, EventArgs e)
    {
        // string connections = ConfigurationManager.ConnectionStrings["SqlConn"].ConnectionString;
        // string connections = "Data Source=VSSPL-002\\SQLEXPRESS;Initial Catalog=employee;Integrated Security=True";
        string myQuery = "select * from employee";
        SqlConnection myConnection = new SqlConnection(connections);
        SqlCommand myCommand = new SqlCommand(myQuery, myConnection);
        myCommand.Connection.Open();
        SqlDataAdapter da = new SqlDataAdapter(myCommand);
        DataSet dt = new DataSet();
        da.Fill(dt);
        DataTable td = dt.Tables[0];
 
         ReportDocument myreport = new ReportDocument();
         string path = Application.startuppath + "~/" + "emp.rpt";
         myreport.Load(path);
         myreport.Database.Tables[0].ApplyLogOnInfo(LogInfo);
         myreport.SetDataSource(td);
         CrystalReportViewer1.ReportSource = myreport;
          // myreport.Load(MapPath("~/" + "emp.rpt"));
         //myreport.Database.Tables[0].SetDataSource(td);
         //CrystalReportViewer1.ReportSource = myreport;
         //int count = Convert.ToInt32(dt.Tables[0].Rows.Count);
         myConnection.Close();
          
      }

Dani AI

Generated

The compile error comes from using Application.StartupPath inside an ASP.NET page (that property is for Windows apps). As noted, use Server.MapPath (or HttpContext.Current.Server.MapPath if you’re outside a Page) to get the physical path. After fixing the path, the usual reason a Crystal report keeps using its original connection is that each report table (and each subreport table) still has the old ConnectionInfo — you must replace it for every table.

Example pattern (safe to paste into your click handler; replace server/database/user/pass):

var report = new ReportDocument();
report.Load(Server.MapPath("~/emp.rpt"));

var conn = new ConnectionInfo {
    ServerName   = "MYSERVER\\SQLEXPRESS",
    DatabaseName = "employee",
    UserID       = "dbuser",
    Password     = "dbpass"
};

// main report tables
foreach (Table t in report.Database.Tables) {
    var tli = t.LogOnInfo;
    tli.ConnectionInfo = conn;
    t.ApplyLogOnInfo(tli);
}

// subreport tables
foreach (ReportDocument sub in report.Subreports) {
    foreach (Table st in sub.Database.Tables) {
        var stli = st.LogOnInfo;
        stli.ConnectionInfo = conn;
        st.ApplyLogOnInfo(stli);
    }
}

CrystalReportViewer1.ReportSource = report;

Notes and troubleshooting

  • Push vs pull: if you prefer to push a DataSet to the report (your code already builds a DataTable), you can call report.SetDataSource(yourDataSet) and skip logon changes — but the dataset schema must match the report. If you want the report to connect directly to SQL (pull mode), use the loop above and also update subreports.
  • If the table owner/schema changed, set table.Location to the fully qualified name (e.g., "dbo.TableName") before applying logon.
  • Don’t swallow exceptions — log them. After use, clear and dispose the ReportDocument (set viewer source to null, then call Close() and Dispose()) to avoid runtime/handle leaks.
  • If using Integrated Security, ensure the app pool identity has DB permissions.

This addresses the path error and the reliable way to override a Database Expert connection for both main and subreport tables.

Application.Startuppath is use to windows application. You use to Server.mappath("")

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.