Data Connectivity
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Data Connectivity
Message Icon Topic: Help with ConnectionString in VS 2008 Post Reply Post New Topic
Author Message
Girac
Newbie
Newbie


Joined: 12 Mar 2009
Location: United States
Online Status: Offline
Posts: 5
Quote Girac Replybullet Topic: Help with ConnectionString in VS 2008
    Posted: 31 Jul 2010 at 7:52pm
Hello all,
I have started moving my reports over to VS 2008.Net web application. I have the report running but I am prompted for database password.

I then set the "Enable database logon prompt" to False and now I receive the logon failed.

I have set the connection string in the web.config but the according to the sql logs that isnt being used. It is being used from the DSN connection.

How and where can I set the connection string/username/password in VS or what am I missing?

Thanks
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 01 Aug 2010 at 5:24pm
You need to call the ReportDocument.SetDatabaseLogin(id,pw) method immediately after calling the Load() method to load the report into a new ReportDocument object variable.
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
KMeyer
Newbie
Newbie


Joined: 03 Jan 2007
Location: Australia
Online Status: Offline
Posts: 22
Quote KMeyer Replybullet Posted: 09 Aug 2010 at 1:40am
Hi Brian,
I have spent 3 days on and off to try and find a simple full example of this for C# which I am assuming would work with the page load. I have not posted for a long time and I am revisiting some old company reports where the data has moved to MS Sql.
 
I guess security was the original idea, but looking at the number of posts from frustrated would be cr developers I am not alone, it could be a little easier to run reports outside the designer when linking to secure databases.
 
I am hoping to find something that does not require half a page of code in the code behind to wade through and interpret when it crashes like many of the old examples seem to do. I even tried the C# sample on pg 377 of your original book which I guess is for VS2003.
 
Any guidence appreciated, I just want to design reports and have them login and run on a database without having to build pages in the code behind.Confused
 
Thank you
Kim
IP IP Logged
KMeyer
Newbie
Newbie


Joined: 03 Jan 2007
Location: Australia
Online Status: Offline
Posts: 22
Quote KMeyer Replybullet Posted: 09 Aug 2010 at 2:31pm
Problem solved for any one else who arrives here and is a novice C# CR developer.
 
Add the following to the code behind .cs page that relates to the page containing your report viewer. Clap
 

using CrystalDecisions.CrystalReports.Engine;

And then in the page load add the following 2 lines
 
protected void Page_Load(object sender, EventArgs e)

{

CrystalReportSource1.ReportDocument.SetDatabaseLogon("user", "pswd","server","database name");

CrystalReportViewer1.ReportSource = CrystalReportSource1;

}

You can leave the server and database out as suggested by Brian's original response, which is simpler again and makes all databases available.
 
I used a SQLOLEDB type connection to a MS SQL database where I had created a restricted user account for the purpose of reports.
I have unchecked "Enable Database Logon Prompting" on the viewer control smart tags/properties.
 
The above assumes CR controls have retained their default names when dragged onto to the page from the VS2005 Toolbox at design time.
Regards
Kim


Edited by KMeyer - 09 Aug 2010 at 2:33pm
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 09 Aug 2010 at 8:42pm
Thanks for posting the update Kim. One correction is that you should use the Page_Init() event and not the Page_Load() event. In VS 2005 and VS 2008 they use ViewState in such a way that you can get unpredictable behavior caused by the viewstate if you don't put your code in Page_Init(). It sounds like everything is working now, and your app won't have any problems. But it's a good habit to get into so that you avoid future potential problems.
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
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 09 Aug 2010 at 8:44pm
Oh - In my original post, I mentioned the Load() event. I meant the ReportDocument.Load() method, not the Page_Load() event. Sorry.

myReport.Load("....");
myReport.SetDatabaseLogin(...);

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
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.016 seconds.