Writing Code
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Writing Code
Message Icon Topic: change logon info at running time(ms access) Post Reply Post New Topic
Author Message
HSoft
Newbie
Newbie
Avatar

Joined: 27 Feb 2007
Location: China
Online Status: Offline
Posts: 8
Quote HSoft Replybullet Topic: change logon info at running time(ms access)
    Posted: 27 Feb 2007 at 9:12pm
hi there,
I'd like to ask the solution for my problem.
I made a new project using ms access 2003,crystal report 9, and visual studio 2005.

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).
After that I made simple report that using DAO connectivity(save data with report option is disabled).

At last I made simple program(windows app) using visual studio 2005.
I put the CrystalReportViewer component, and these is the code :


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace prj
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void crystalReportViewer1_Load(object sender, EventArgs e)
        {
           
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            crystalReportViewer1.ReportSource = System.Environment.CurrentDirectory + "\\Report1.rpt";
            crystalReportViewer1.LogOnInfo[0].ConnectionInfo.UserID = "Admin";
            crystalReportViewer1.LogOnInfo[0].ConnectionInfo.Password = "12";
            crystalReportViewer1.LogOnInfo[0].ConnectionInfo.DatabaseName = System.Environment.CurrentDirectory + "\\db.mdb";
            crystalReportViewer1.LogOnInfo[0].ConnectionInfo.ServerName = System.Environment.CurrentDirectory + "\\db.mdb";
        }
    }
}


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,
my question is how must I write in the program so that the box doesnt come out.

thanks



Edited by HSoft - 27 Feb 2007 at 9:22pm
IP IP Logged
HSoft
Newbie
Newbie
Avatar

Joined: 27 Feb 2007
Location: China
Online Status: Offline
Posts: 8
Quote HSoft Replybullet Posted: 04 Mar 2007 at 6:24pm
could anyone help please ?
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 05 Mar 2007 at 1:43am
Hey - sorry I can't chime in yet. I've been buried in the XI book and haven't had time to debug your code for 2005. If I was using 2003, I would first instantiate a new LogonInfo object, assign its properties as you did (but skip DatabaseName b/c its already in the ServerName property) and then add the object to the viewer's LogonInfo class. After that I would assign the report to the ReportSource property. But again, I haven't had time to do it in 2005 yet to see if this is still a recommended way or not. 
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
HSoft
Newbie
Newbie
Avatar

Joined: 27 Feb 2007
Location: China
Online Status: Offline
Posts: 8
Quote HSoft Replybullet Posted: 05 Mar 2007 at 6:15pm
ok, thanks to your effort for helping me bro

I'll try first
IP IP Logged
HSoft
Newbie
Newbie
Avatar

Joined: 27 Feb 2007
Location: China
Online Status: Offline
Posts: 8
Quote HSoft Replybullet Posted: 05 Mar 2007 at 7:10pm
Originally posted by BrianBischof

Hey - sorry I can't chime in yet. I've been buried in the XI book and haven't had time to debug your code for 2005. If I was using 2003, I would first instantiate a new LogonInfo object, assign its properties as you did (but skip DatabaseName b/c its already in the ServerName property) and then add the object to the viewer's LogonInfo class. After that I would assign the report to the ReportSource property. But again, I haven't had time to do it in 2005 yet to see if this is still a recommended way or not. 


I've change the code into this :


        private void Form1_Load(object sender, EventArgs e)
        {

ConnectionInfo crConnectionInfo = new ConnectionInfo();
crConnectionInfo.UserID = "Admin";
crConnectionInfo.Password = "12";
            crystalReportViewer1.ReportSource = System.Environment.CurrentDirectory + "\\Report1.rpt";
            crystalReportViewer1.LogOnInfo[0].ConnectionInfo = crConnectionInfo;
           
        }

but the error still there.

FYI , once again, I change the database file location,
so the location when I made the report and when I tried to run the program is different, so I change the server/database name property.



Edited by HSoft - 05 Mar 2007 at 7:14pm
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 05 Mar 2007 at 7:45pm
Check out this post. He is coding it the way I recommend in my book. See if you can apply this to your report. As another idea, create a simple database with no security. Then get the code to work with ONLY changing the database location. If you get that working, then turn on user security. That way you aren't potentially trying to fix two bugs at once without realizing it. Just focus on getting location to work using this code and then add on.

http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=275
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
HSoft
Newbie
Newbie
Avatar

Joined: 27 Feb 2007
Location: China
Online Status: Offline
Posts: 8
Quote HSoft Replybullet Posted: 05 Mar 2007 at 11:52pm
thanks bro, solved with this

        private void Form1_Load(object sender, EventArgs e)
        {
            ReportDocument crReport = new ReportDocument();
            string sTemplatePath = System.Environment.CurrentDirectory + "\\Report1.rpt";
            crReport.Load(sTemplatePath);
            TableLogOnInfo crTableLogOnInfo = new TableLogOnInfo();
            ConnectionInfo tConnInfo = new ConnectionInfo();
            tConnInfo.DatabaseName = System.Environment.CurrentDirectory + "\\db.mdb";
            tConnInfo.Password = "12";
            foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crReport.Database.Tables)
            {
                crTableLogOnInfo = crTable.LogOnInfo;
                crTableLogOnInfo.ConnectionInfo = tConnInfo;
                crTable.ApplyLogOnInfo(crTableLogOnInfo);
            }

            crystalReportViewer1.ReportSource = crReport;
        }


I'll try in my another project, thanks again
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.012 seconds.