hi every body

i have a trouble with viewing the report from using the following environments

C# - Crystalreport - Oracle database

i regularly use the basic way to call a view form the database and extract the data form it like that

cmd.commandtext= "Create view  as select * from table1 where icode = '10'";

cmd.excutenonquery();

and then create a report depending on this view

and regally connect your report viewer with this view

and its working with viewing the report via crystalreport
it's absolutely good for access database ans SQL server
but i's so bad when dealing with oracle database

when i use this past method i found a messagebox showing tell me that it need the user password in oracle database

so i have a trouble to make instance from my report in c#

i follow the following method but it also doesn't work !!

OleDbConnection cn = new OleDbConnection();
OleDbCommand cmdtest = new OleDbCommand();
OleDbDataReader drrr;
OleDbDataAdapter ad = new OleDbDataAdapter();
DataTable dt = new DataTable();
if (cn.State == ConnectionState.Closed)
{
cn.ConnectionString = "provider=oraoledb.oracle.1;password=123;user id = system;";
cn.Open();
}
DataSet ds = new DataSet();
cmdtest.Connection = cn;
cmdtest.CommandType = CommandType.Text;
cmdtest.CommandText = "select * from doc ";
drrr = cmdtest.ExecuteReader();
drrr.Close();
CrystalDecisions.CrystalReports.Engine.ReportClass ss = new CrystalDecisions.CrystalReports.Engine.ReportClass();
ad.SelectCommand = cmdtest;
ad.Fill(ds, "doc");
ss.ResourceName = "docreport.rpt";
ss.SetDataSource(ds.Tables["doc"]);
crystalReportViewer1.ReportSource = ss;

so if you have any idea what i'm wrong about please tell me

thanks a lot

Recommended Answers

All 4 Replies

It sounds like you need to set the report's connection info for each of the tables. Try passing in the ReportDocument to this after you have set the table parameters, but before attempting to run/view the report:

public static void ReportSourceSetup(ReportDocument crDoc, ConnectionInfo crConnectionInfo)
        {
            // Each table in report needs to have logoninfo setup:
            Tables crTables = crDoc.Database.Tables;
            foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crTables)
            {
                TableLogOnInfo crTableLogonInfo = crTable.LogOnInfo;
                crTableLogonInfo.ConnectionInfo = crConnectionInfo;
                crTable.ApplyLogOnInfo(crTableLogonInfo);
            }
        }

Hi samehsenosi,

Datasource is not specified in the connection string.

Set the data source and try it again.

hi DdoubleD

most thanks about your share
but if you tell me the complete right way for this problem !!!
cause i try to follow your steps but there's something missing in my steps...

so please tell me the whole way to it

thanks a lot


It sounds like you need to set the report's connection info for each of the tables. Try passing in the ReportDocument to this after you have set the table parameters, but before attempting to run/view the report:

public static void ReportSourceSetup(ReportDocument crDoc, ConnectionInfo crConnectionInfo)
        {
            // Each table in report needs to have logoninfo setup:
            Tables crTables = crDoc.Database.Tables;
            foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crTables)
            {
                TableLogOnInfo crTableLogonInfo = crTable.LogOnInfo;
                crTableLogonInfo.ConnectionInfo = crConnectionInfo;
                crTable.ApplyLogOnInfo(crTableLogonInfo);
            }
        }

samehsenosi

Is this what you are looking for?:

private void RunMyReport(ReportDocument crDoc)
        {
            ConnectionInfo crConnectionInfo = new ConnectionInfo();
            crConnectionInfo.ServerName = "YOUR SERVER NAME";
            crConnectionInfo.DatabaseName = "YOUR DATABASE NAME";
            crConnectionInfo.UserID = "YOUR DATABASE USERNAME";
            crConnectionInfo.Password = "YOUR DATABASE PASSWORD";
            
            // setup before passing to the viewer...
            ReportSourceSetup(crDoc, crConnectionInfo);

            crystalReportViewer1.ReportSource = crDoc;
            crystalReportViewer1.Refresh();
        }
        public static void ReportSourceSetup(ReportDocument crDoc, ConnectionInfo crConnectionInfo)
        {
            // Each table in report needs to have logoninfo setup:
            Tables crTables = crDoc.Database.Tables;
            foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crTables)
            {
                TableLogOnInfo crTableLogonInfo = crTable.LogOnInfo;
                crTableLogonInfo.ConnectionInfo = crConnectionInfo;
                crTable.ApplyLogOnInfo(crTableLogonInfo);
            }
        }

// calling...
        RunMyReport(ss);
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.