Skip to Content
0
Jan 25, 2021 at 08:21 AM

[Database Vendor Code:17 ] Failed to open the connection contain subreports

51 Views Last edit Jan 26, 2021 at 02:16 PM 2 rev

I develop an application it works on development pc but when I deploy it also work and shows all reports without those reports which contain sub reports it shows me this error

<code>ReportDocument rd;
    private void FeeVoucher_Load(object sender, EventArgs e)
    {
        MaximizedBounds = Screen.FromHandle(this.Handle).WorkingArea;
        WindowState = FormWindowState.Maximized;
     
        try
        {
            SqlConnection conn = new SqlConnection("Data Source=(LocalDB)\v11.0;AttachDbFilename='|DataDirectory|\StudentManagement.mdf';Integrated Security=True;");
            SqlCommand cmd = new SqlCommand("usp_ReportingFeeVoucher", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            conn.Open();
            if (this.PId == null)
            {
                cmd.Parameters.AddWithValue("@FeePaymentId", DBNull.Value);
            }
            else
            {
                cmd.Parameters.AddWithValue("@FeePaymentId", this.PId);
            }
            if (this.f == null && this.l == null)
            {
                cmd.Parameters.AddWithValue("@fId", DBNull.Value);
                cmd.Parameters.AddWithValue("@lId", DBNull.Value);

            }
            else
            {
                cmd.Parameters.AddWithValue("@fId", this.f);
                cmd.Parameters.AddWithValue("@lId", this.l);
            }
            SqlDataAdapter da1 = new SqlDataAdapter(cmd);
            DataTable dt1 = new DataTable();
            da1.Fill(dt1);
            rd = new ReportDocument();

            string path = Application.StartupPath + @"..\..\..\";

            rd.Load(Path.GetFullPath(Path.Combine(path + @"\\CrystalReports\\FeeVoucher3in1.rpt")));
            //       rd.Load(Application.StartupPath + "\\StudentCrystalReport.rpt");
            rd.SetDataSource(dt1);
            for (int i = 0; i < rd.Subreports.Count; i++)
            {
                rd.Subreports[i].SetDatabaseLogon("", "", "(LocalDB)\v11.0", "'|DataDirectory|\\StudentManagement.mdf'");
            }
            
            crystalReportViewer1.ReportSource = rd;
            crystalReportViewer1.RefreshReport();
        }
        catch (Exception ex)
        {
            if (rd != null)
            {
                rd.Close();
            }
            MessageBox.Show(ex.Message);
        }
    }

I Add this code after some search but it also doesn't work.

<code>for (int i = 0; i < rd.Subreports.Count; i++)
                {
                    rd.Subreports[i].SetDatabaseLogon("", "", "(LocalDB)\v11.0", "'|DataDirectory|\\StudentManagement.mdf'");
                }

Attachments

capture.png (12.4 kB)