Problem connecting to database using crystal report

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mohammed Seidu
    New Member
    • Sep 2007
    • 19

    Problem connecting to database using crystal report

    Hi all,
    Can anyone help me on how to create crystal reports in a .net windows application?

    The problem is, i have an OleDbConnection object named 'conn' which I create dynamically to connect to an access database and i want to use this connection to create crystal reports.

    I would welcome any help or alternative.

    Thank you all in advance.
  • Shashi Sadasivan
    Recognized Expert Top Contributor
    • Aug 2007
    • 1435

    #2
    A crystal report consists information of tables in a database. Each table can be attached to a different database, and hence you should set the database connection of each individual table

    CrystalDecision s.CrystalReport s.Engine.Table

    The table property has a TableLogOnInfo Property which then has a connectionInfo property. Set this connection info property

    CrystalDecision s.Shared.Connec tionInfo

    you would need to set the datasource, database name, userid password if apllicable, etc

    Comment

    • nev
      Contributor
      • Oct 2007
      • 251

      #3
      Originally posted by Mohammed Seidu
      Hi all,
      Can anyone help me on how to create crystal reports in a .net windows application?

      The problem is, i have an OleDbConnection object named 'conn' which I create dynamically to connect to an access database and i want to use this connection to create crystal reports.

      I would welcome any help or alternative.

      Thank you all in advance.
      Here is an amazing link for your problem.

      Comment

      • Mohammed Seidu
        New Member
        • Sep 2007
        • 19

        #4
        Thank you for the link, it is very useful.

        Comment

        • Mohammed Seidu
          New Member
          • Sep 2007
          • 19

          #5
          Originally posted by Shashi Sadasivan
          A crystal report consists information of tables in a database. Each table can be attached to a different database, and hence you should set the database connection of each individual table

          CrystalDecision s.CrystalReport s.Engine.Table

          The table property has a TableLogOnInfo Property which then has a connectionInfo property. Set this connection info property

          CrystalDecision s.Shared.Connec tionInfo

          you would need to set the datasource, database name, userid password if apllicable, etc
          Thank you for the help. I tried using the idea to connect but I am not yet success. Please tell me what is wrong with this code bcus it fails to connect and I am prompted to provide the connection credentials.

          /*
          Note: I am using a passworded access database
          (1) The code below fails to connect to the tables in the database and I don't know why.
          (2) The second problem is the user id, what if someone logs in as a user other than Administrator?
          */

          private void daily_report_fr m_Load(object sender, System.EventArg s e)
          {
          //report object
          date_report drpt=new date_report();
          //inits
          TableLogOnInfo logOnInfo = new TableLogOnInfo ();
          int i = 0;

          // Loop through every table in the report.
          for (i=0;i == drpt.Database.T ables.Count - 1;i++)
          {
          // Set the connection information for the current table.
          logOnInfo.Conne ctionInfo.Serve rName = "";
          logOnInfo.Conne ctionInfo.Datab aseName = "";
          logOnInfo.Conne ctionInfo.UserI D = "Admin";
          logOnInfo.Conne ctionInfo.Passw ord = "db_passwor d";
          drpt.Database.T ables [i].ApplyLogOnInfo (logOnInfo);
          //test connectivity
          MessageBox.Show (drpt.Database. Tables[i].TestConnectivi ty().ToString() );
          }



          //report view
          this.daily_repo rt_viewer.Repor tSource=drpt;
          }

          Comment

          • Shashi Sadasivan
            Recognized Expert Top Contributor
            • Aug 2007
            • 1435

            #6
            You have not specified which server and databse to connect to.
            Have a look at your connection string that you use. The serverName is the datasource, and the databaseName is the initial catalog.

            Without these the crystal repost dose not know where to connect to.

            Originally posted by Mohammed Seidu
            Thank you for the help. I tried using the idea to connect but I am not yet success. Please tell me what is wrong with this code bcus it fails to connect and I am prompted to provide the connection credentials.

            /*
            Note: I am using a passworded access database
            (1) The code below fails to connect to the tables in the database and I don't know why.
            (2) The second problem is the user id, what if someone logs in as a user other than Administrator?
            */

            private void daily_report_fr m_Load(object sender, System.EventArg s e)
            {
            //report object
            date_report drpt=new date_report();
            //inits
            TableLogOnInfo logOnInfo = new TableLogOnInfo ();
            int i = 0;

            // Loop through every table in the report.
            for (i=0;i == drpt.Database.T ables.Count - 1;i++)
            {
            // Set the connection information for the current table.
            logOnInfo.Conne ctionInfo.Serve rName = "";
            logOnInfo.Conne ctionInfo.Datab aseName = "";
            logOnInfo.Conne ctionInfo.UserI D = "Admin";
            logOnInfo.Conne ctionInfo.Passw ord = "db_passwor d";
            drpt.Database.T ables [i].ApplyLogOnInfo (logOnInfo);
            //test connectivity
            MessageBox.Show (drpt.Database. Tables[i].TestConnectivi ty().ToString() );
            }



            //report view
            this.daily_repo rt_viewer.Repor tSource=drpt;
            }

            Comment

            • Mohammed Seidu
              New Member
              • Sep 2007
              • 19

              #7
              The code I submitted works fine when connecting to ms sql server without the serverName and databaseName and even without user id on my system. But the problem is that I tried what you suggested and did not work because may be I am connecting an access database and not sql server. The second possibility may be how I connected to the database using crystal report.
              If I connect using ODBC would I need to create the DSN on the deployment machine?

              I have tried several times connecting my access database using this form with the fields below could anyone tell me exactly what they want?

              Database Name: ............... ......
              Database Type:....Access
              User ID:....Admin
              Password: ...............
              Jet System Database: .........
              Jet Database Password: ............... .


              Originally posted by Shashi Sadasivan
              You have not specified which server and databse to connect to.
              Have a look at your connection string that you use. The serverName is the datasource, and the databaseName is the initial catalog.

              Without these the crystal repost dose not know where to connect to.

              Comment

              • Mohammed Seidu
                New Member
                • Sep 2007
                • 19

                #8
                Thank you all.
                I finally was enable to connect to my access database through crystal report.
                The database name: is the path to the database file
                User ID: not neccessary
                Password: not neccessary
                Jet System database: C:\Documents and Settings\Admini strator\Applica tion Data\Microsoft\ Access\System.m dw
                Jet Database password: password of access file

                I am now working on trying to display the crystal report in my application (connecting to the tables involved at run time).
                Any help would be welcomed.

                Originally posted by Mohammed Seidu
                The code I submitted works fine when connecting to ms sql server without the serverName and databaseName and even without user id on my system. But the problem is that I tried what you suggested and did not work because may be I am connecting an access database and not sql server. The second possibility may be how I connected to the database using crystal report.
                If I connect using ODBC would I need to create the DSN on the deployment machine?

                I have tried several times connecting my access database using this form with the fields below could anyone tell me exactly what they want?

                Database Name: ............... ......
                Database Type:....Access
                User ID:....Admin
                Password: ...............
                Jet System Database: .........
                Jet Database Password: ............... .

                Comment

                Working...