IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Connectivité Discussion :

[CR 9] [ASPX][C#]connexion via code


Sujet :

Connectivité

  1. #1
    Membre actif

    Inscrit en
    Août 2002
    Messages
    302
    Détails du profil
    Informations personnelles :
    Âge : 42

    Informations forums :
    Inscription : Août 2002
    Messages : 302
    Points : 285
    Points
    285
    Par défaut [CR 9] [ASPX][C#]connexion via code
    est ce qu'on pourrait effectuer la connexion à une base de données via code et non en paramétrant le report. le problème avec crystal report est que lorsque on fait un report qui se connecte sur une base X, le report ne fonctionnera pas sur une base Y. est ce qu'il existe une solution à ce problème.
    Merci

  2. #2
    Membre confirmé
    Avatar de sur_uix
    Profil pro
    Inscrit en
    Mai 2002
    Messages
    379
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2002
    Messages : 379
    Points : 550
    Points
    550
    Par défaut
    Oui on peut modifier la connexion via code

    Voici un exemple en VB avec ADO et le moteur CRAXDRT de Crystal
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    How to change the data source
    This example demonstrates how to change the data source from native Access to an OLEDB (ADO) data source by using the ConnectionProperty Object, as well as how to change the table name by using the Location property of the DatabaseTable Object,. CrystalReport1 is connected to the xtreme.mdb database found in the \Program Files\Crystal Decisions\Crystal Reports 9\Samples\En\Databases folder. The report is using the Customer table. A copy of the Customer table is added to the pubs database on Microsoft SQL Server.
     
     
    ' Create a new instance of the report.
    Dim Report As New CrystalReport1
     
    Private Sub Form_Load()
    ' Declare a ConnectionProperties collection.
    Dim CPProperties As CRAXDRT.ConnectionProperties
    ' Declare a DatabaseTable object.
    Dim DBTable As CRAXDRT.DatabaseTable
     
    ' Get the first table in the report.
    Set DBTable = Report.Database.Tables(1)
     
    ' Get the collection of connection properties.
    Set CPProperties = DBTable.ConnectionProperties
     
    ' Change the database DLL used by the report from
    ' native Access (crdb_dao.dll) to ADO/OLEDB (crdb_ado.dll).
    DBTable.DllName = "crdb_ado.dll"
     
    '  The connection property bags contain the name and value
    ' pairs for the native Access DLL (crdb_dao.dll). So we need
    ' to clear them, and then add the name and value pairs that
    ' are required to connect to the OLEDB data source.
     
    ' Clear all the ConnectioProperty objects from the collection.
    CPProperties.DeleteAll
     
    ' Add the name value pair for the provider.
    CPProperties.Add "Provider", "SQLOLEDB"
     
    ' Add the name value pair for the data source (server).
    CPProperties.Add "Data Source", "ServerA"
     
    ' Add the name value pair for the database.
    CPProperties.Add "Initial Catalog", "pubs"
     
    ' Add the name value pair for the user name.
    CPProperties.Add "User ID", "UserName"
     
    ' Add the name value pair for the password.
    CPProperties.Add "Password", "password"
     
    ' Set the table name.
    DBTable.Location = "Customer"
     
    Screen.MousePointer = vbHourglass
    ' Set the report source of the viewer and view the report.
    CRViewer91.ReportSource = Report
    CRViewer91.ViewReport
    Screen.MousePointer = vbDefault
    End Sub

  3. #3
    Membre actif

    Inscrit en
    Août 2002
    Messages
    302
    Détails du profil
    Informations personnelles :
    Âge : 42

    Informations forums :
    Inscription : Août 2002
    Messages : 302
    Points : 285
    Points
    285
    Par défaut
    le moteur CRAXDRT de Crystal
    qu'est ce que le moteur CRAXDRT de Crystal et quel est le package qu'on doit importer?
    Merci

  4. #4
    Membre confirmé
    Avatar de sur_uix
    Profil pro
    Inscrit en
    Mai 2002
    Messages
    379
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2002
    Messages : 379
    Points : 550
    Points
    550
    Par défaut
    Pour pouvoir utiliser un rapport crytsal depuis un outil de développement .Net VB Delphi etc... il faut 1. la version Developpeur de Crystal puis utiliser un des moteurs de Crystal.
    Pour C# il ne faut pas prendre le RDC (CRaxdrt) mais le RAS - COM Report Application Server SDK

    Je n'y connais rien en C#, mais voici un petit exemple
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    //********************************************
    //
    //File Name:     	SimpleLogonEngine.sln
    //Created:       	May 30, 2002
    //Author ID:     	CHO
    //Purpose:       	This C# .NET sample web application
    //                  demonstrates how to log on to a secure SQL database 
    //                  using the database table objects of the ReportDocument 
    //                  class to establish the connection.  This application 
    //                  uses "Engine" in its title because it uses objects in 
    //                  the CrystalDecisions.CrystalReports.Engine assembly to log 
    //                  on to the database.
    //
    //********************************************
     
    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 CrystalDecisions.CrystalReports.Engine;
    using CrystalDecisions.Shared;
     
    namespace SimpleLogonEngine
    {
    	/// <summary>
    	/// Summary description for WebForm1.
    	/// </summary>
    	public class WebForm1 : System.Web.UI.Page
    	{
    		protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1;
     
    		// CR variables
    		CrystalReport1 crReportDocument;
    		Database crDatabase;
    		Tables crTables;
    		TableLogOnInfo crTableLogOnInfo;
    		ConnectionInfo crConnectionInfo;
     
     
    		private void Page_Load(object sender, System.EventArgs e)
    		{
    			// Put user code to initialize the page here
    		}
     
    		#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);
     
    			//Create an instance of the strongly-typed report object
    			crReportDocument = new CrystalReport1();
     
    			//Create a new instance of the connectioninfo object and
    			//set its properties
    			//Note: This sample report connects to the sample SQL Server database, Pubs,
    			//If you have access to SQL server, enter in your values for the ServerName,
    			//UserID and Password properties to connect.  The report included with this
    			//sample application connects using OLE DB and SQL authentication.
     
    			crConnectionInfo = new ConnectionInfo();
    			crConnectionInfo.ServerName = "Enter your server name";
    			crConnectionInfo.DatabaseName = "Enter the database name";
    			crConnectionInfo.UserID = "Enter the User ID";
    			crConnectionInfo.Password = "Enter the password";
     
    			//Get the tables collection from the report object
    			crDatabase = crReportDocument.Database;
    			crTables = crDatabase.Tables;
     
    			//Apply the logon information to each table in the collection
    			foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crTables)
    			{		
    				crTableLogOnInfo = crTable.LogOnInfo;
    				crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
    				crTable.ApplyLogOnInfo(crTableLogOnInfo);
    			}
     
    			//Once the connection to the database has been established for
    			//each table in the report, the report object can be bound to the viewer
    			//using the reportsource property of the viewer to display the report.
    			CrystalReportViewer1.ReportSource = crReportDocument;
    		}
     
    		/// <summary>
    		/// Required method for Designer support - do not modify
    		/// the contents of this method with the code editor.
    		/// </summary>
    		private void InitializeComponent()
    		{    
    			this.Load += new System.EventHandler(this.Page_Load);
     
    		}
    		#endregion
    	}
    }
    Le projet complet est ici
    http://support.crystaldecisions.com/...engine.exe.asp

    Bonne chance

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. connexion via asp ou php ?
    Par cege dans le forum 4D
    Réponses: 5
    Dernier message: 25/01/2006, 08h43
  2. probleme de connexion via un poste distant
    Par leghola dans le forum MS SQL Server
    Réponses: 2
    Dernier message: 12/09/2005, 11h51
  3. [interbase5] problem au connexion via le serveur
    Par inconu dans le forum InterBase
    Réponses: 1
    Dernier message: 31/07/2005, 00h24
  4. pb de connexion via Kylix2
    Par nadine.mauch dans le forum PostgreSQL
    Réponses: 2
    Dernier message: 22/09/2003, 09h29

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo