Forum Post: RE: Connecting to database on 64 bit server via ODBC and .NET

Status
Not open for further replies.
N

newport1

Guest
I never answered in this post since I've been too busy with a lot of projects but I finally asked a developer to take a look at it and he was very helpful and came up with an answer. Here is the code that should work (at least it works for us). Note that the code below is just a snippet of my complete code. The rest however is default code for some forms/buttons/etc so not necessary for the example. I hope it will help anyone who is struggling with Crystal Reports: /* Parameters Definitions */ /* Local Variable Definitions */ DEFINE VARIABLE crystalReportViewer1 AS CrystalDecisions.Windows.Forms.CrystalReportViewer NO-UNDO. DEFINE VARIABLE FormObjectRef AS CLASS Progress.Windows.Form NO-UNDO. DEFINE VARIABLE crwReport AS CrystalDecisions.CrystalReports.Engine.ReportDocument NO-UNDO. DEFINE VARIABLE tblLogonInfo AS CrystalDecisions.Shared.TableLogOnInfo NO-UNDO. DEFINE VARIABLE crRptTable AS CrystalDecisions.CrystalReports.Engine.Table NO-UNDO. DEFINE VARIABLE OKpressed AS LOGICAL NO-UNDO INITIAL FALSE. /* Connection variables */ DEFINE VARIABLE lv-DSN AS CHARACTER NO-UNDO. DEFINE VARIABLE lv-odbc AS CHARACTER INIT "Progress OpenEdge 11.2 Driver" NO-UNDO. DEFINE VARIABLE lv-Server AS CHARACTER INIT "servername" NO-UNDO. /* Name of the server */ DEFINE VARIABLE lv-dbname AS CHARACTER INIT "dbname" NO-UNDO. /* Name of the database */ DEFINE VARIABLE lv-User AS CHARACTER INIT "username" NO-UNDO. /* Username */ DEFINE VARIABLE lv-Pass AS CHARACTER INIT "password" NO-UNDO. /* Password */ DEFINE VARIABLE lv-Port AS CHARACTER INIT "port" NO-UNDO. /* Port */ FormObjectRef = NEW Progress.Windows.Form(). CrystalReportViewer1 = NEW CrystalDecisions.Windows.Forms.CrystalReportViewer(). crwReport = NEW CrystalDecisions.CrystalReports.Engine.ReportDocument(). crwReport:Load(fiReportLocation:SCREEN-VALUE). /*crwReport:Load("name_of_report_to_load").*/ FormObjectRef:Controls:Add(crystalReportViewer1). FormObjectRef:Size = NEW System.Drawing.Size(820, 520). /* Create an DSN */ lv-dsn = "DRIVER=" + lv-odbc + ";HOST=" + lv-Server + ";PORT=" + lv-Port + ";DB=" + lv-dbname + ";UID=" + lv-user + ";PWD=" + lv-Pass. /* Based on code from msdn.microsoft.com/.../ms226184(v=vs.80).aspx */ /* Removed reference to DatabaseName property - is covered by DB in lv-dsn and, if set, ODBC driver complains about duplicated parameter and connection fails */ crwReport:SetDatabaseLogon(lv-User, lv-Pass). DO i = 0 TO crwReport:Database:Tables:Count - 1: crRptTable = crwReport:Database:Tables. tblLogonInfo = crRptTable:LogOnInfo. tblLogonInfo:ConnectionInfo:ServerName = lv-dsn. tblLogonInfo:ConnectionInfo:UserID = lv-User. tblLogonInfo:ConnectionInfo:password = lv-Pass. crRptTable:ApplyLogOnInfo(tblLogonInfo). END. crystalReportViewer1:ActiveViewIndex = -1. crystalReportViewer1:BorderStyle = System.Windows.Forms.BorderStyle:FixedSingle. crystalReportViewer1:Cursor = System.Windows.Forms.Cursors:Default. crystalReportViewer1:Dock = System.Windows.Forms.DockStyle:Fill. crystalReportViewer1:Location = NEW System.Drawing.Point(0, 0). crystalReportViewer1:Name = "crystalReportViewer1". crystalReportViewer1:Size = NEW System.Drawing.Size(300, 300). crystalReportViewer1:TabIndex = 0. crystalReportViewer1:AutoScaleDimensions = NEW System.Drawing.SizeF(Progress.Util.CastUtil:ToSingle(6), Progress.Util.CastUtil:ToSingle(13)). crystalReportViewer1:AutoSize = TRUE. crystalReportViewer1:BackColor = System.Drawing.SystemColors:Desktop. crystalReportViewer1:ReportSource = crwReport. crystalReportViewer1:ResumeLayout(FALSE). crystalReportViewer1:RefreshReport(). FormObjectRef:StartPosition = System.Windows.Forms.FormStartPosition:CenterScreen. FormObjectRef:Text = "Crystal Report Viewer". WAIT-FOR FormObjectRef:ShowDialog().

Continue reading...
 
Status
Not open for further replies.
Top