cancel
Showing results for 
Search instead for 
Did you mean: 

change logon info at running time(using ms access)

Former Member
0 Kudos

hi there,<br />I&#39;d like to ask the solution for my problem.<br />I made a new project using ms access 2003,crystal report 9, and visual studio 2005.<br /><br />I just made a simple access dbase with 1 table(Table 1) and protected with password, o I forgot this table has 2 field(id and desc).<br />After that I made simple report that using DAO connectivity(save data with report option is disabled).<br /><br />At last I made simple program(windows app) using visual studio 2005.<br />I put the CrystalReportViewer component, and these is the code :<br /><br />

<br />using System;<br />using System.Collections.Generic;<br />using System.ComponentModel;<br />using System.Data;<br />using System.Drawing;<br />using System.Text;<br />using System.Windows.Forms;<br /><br />namespace prj<br />{<br />   public partial class Form1 : Form<br />   {<br />       public Form1()<br />       {<br />           InitializeComponent();<br />       }<br /><br />       private void crystalReportViewer1_Load(object sender, EventArgs e)<br />       {<br /><br />       }<br /><br />       private void Form1_Load(object sender, EventArgs e)<br />       {<br />           crystalReportViewer1.ReportSource = System.Environment.CurrentDirectory + "\Report1.rpt";<br />           crystalReportViewer1.LogOnInfo[0].ConnectionInfo.UserID = "Admin";<br />           crystalReportViewer1.LogOnInfo[0].ConnectionInfo.Password = "12";<br />           crystalReportViewer1.LogOnInfo[0].ConnectionInfo.DatabaseName = System.Environment.CurrentDirectory + "\db.mdb";<br />           crystalReportViewer1.LogOnInfo[0].ConnectionInfo.ServerName = System.Environment.CurrentDirectory + "\db.mdb";<br />       }<br />   }<br />}<br />

<br /><br />and the problem is when I move the access database file to other location, the viewer shows a box to be confirmed by my UserID and password,<br />my question is how must I write in the program so that the box doesnt come out.<br /><br />thanks

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

for c#:

-


private void ConfigureCrystalReports()

{

ConnectionInfo connectionInfo = new ConnectionInfo();

connectionInfo.UserID = "Admin";

connectionInfo.Password = "";

connectionInfo.AllowCustomConnection = false;

connectionInfo.ServerName = @"C:\...\Nombre.mdb";

connectionInfo.DatabaseName = @"C:\...\Nombre.mdb";

TableLogOnInfo crTableLogonInfo = new TableLogOnInfo();

Database crDatabase = null;

Tables crTables = null;

//your CR

CrystalReport1 oC = new CrystalReport1();

crDatabase = oC.Database;

crTables = oC.Database.Tables;

foreach (Table crTable in crTables)

{

crTableLogonInfo = crTable.LogOnInfo;

crTableLogonInfo.ConnectionInfo = connectionInfo;

crTable.ApplyLogOnInfo(crTableLogonInfo);

}

crystalReportViewer.ReportSource = oC;

SetDBLogonForReport(connectionInfo);

}

private void Form1_Load(object sender, EventArgs e)

{

ConfigureCrystalReports();

}

private void crystalReportViewer_Load(object sender, EventArgs e)

{

}

private void SetDBLogonForReport(ConnectionInfo connectionInfo)

{

TableLogOnInfos tableLogOnInfos = crystalReportViewer.LogOnInfo;

foreach (TableLogOnInfo tableLogOnInfo in tableLogOnInfos)

{

tableLogOnInfo.ConnectionInfo = connectionInfo;

}

}

-


or for the VB:

Dim cr1

Dim myTable As CrystalDecisions.CrystalReports.Engine.Table

Dim myLogin As CrystalDecisions.Shared.TableLogOnInfo

'Crystal Report Variables

Dim crReportDocument As New Reportrpt

Dim crConnectionInfo As New ConnectionInfo

Dim crTableLogonInfo As New TableLogOnInfo

Dim crDatabase As CrystalDecisions.CrystalReports.Engine.Database

Dim crTables As CrystalDecisions.CrystalReports.Engine.Tables

Dim crTable As CrystalDecisions.CrystalReports.Engine.Table

Dim path1 As String = Application.StartupPath & "\AnsonsAccounting.mdb"

With crConnectionInfo

'.DatabaseName = path1 'If you are connecting to Access through ODBC, then set the 'DatabaseName' for the ConnectionInfo' object as follows:

.ServerName = path1 'If you are connecting to Access through OLE DB, then set set the 'ServerName':

.UserID = "Admin"

.Password = ""

End With

crDatabase = crReportDocument.Database

crTables = crDatabase.Tables

For Each crTable In crReportDocument.Database.Tables

crTableLogonInfo = crTable.LogOnInfo

crTableLogonInfo.ConnectionInfo = crConnectionInfo

crTable.ApplyLogOnInfo(crTableLogonInfo)

Next

-


stolen from the:

http://www.velocityreviews.com/forums/t80454-crystal-reports-quotlogon-failedquot-for-access-databas...

Answers (1)

Answers (1)

Former Member
0 Kudos

anyone could help ?