Solved

Crystal Report asking for DB login

Posted on 2015-01-24
7
171 Views
Last Modified: 2015-07-07
Hi,

I am using Visual Studio 2008 with Crystal Report engine provided with VS.
I create couple of reports that display properly in the crystalreportviewer on my development machine.
But, when I publish my site to the production server the report won't open and the system ask for the DB username and password login.

On my development machine I am using window integrated security while on the production server I am using "sa" login to connect to the DB.

I added the following code lines to my code, but the report is still asking for the DB login:

cryRpt.SetDatabaseLogon("sa", "dbadmin", "Hyper_Server", "myDB")

I need help please!
0
Comment
Question by:pascalmartin
7 Comments
 
LVL 32

Expert Comment

by:Daniel Wilson
ID: 40568200
You need to set each table's logon info.

Something like ...
        Dim crtableLogoninfo As New TableLogOnInfo
        Dim crConnectionInfo As New ConnectionInfo
        with crConnectionInfo
           .Server = "Hyper_Server"
           .DatabaseName = "myDB"
           .UserName = "" 'for Integrated security
           .password = ""
         end with

For Each dbTable As Table In cryRpt.Database.Tables
  crtableLogoninfo = dbTable.LogOnInfo
   crtableLogoninfo.ConnectionInfo = crConnectionInfo

   dbTable.ApplyLogOnInfo(crtableLogoninfo)
next

Open in new window


That code block is cut up and put back together from a complex project, so I probably missed something.  But hopefully it's close enough to get you headed in the right direction.
0
 

Author Comment

by:pascalmartin
ID: 40568263
Thanks, I shall try that Monday when back at work where is the production server...
Keep you posted.
0
 
LVL 80

Accepted Solution

by:
David Johnson, CD, MVP earned 500 total points
ID: 40569303
NO POINTS
Another way
 'Declarations
  Public CRReport As CrystalDecisions.CrystalReports.Engine.ReportDocument
  Public CRTable As CrystalDecisions.CrystalReports.Engine.Table
  Public CRTLI As CrystalDecisions.Shared.TableLogOnInfo

  'some procedure
  CRReport = New CrystalDecisions.CrystalReports.Engine.ReportDocument
  CRReport.Load(GRutaRpts & "MyReport.rpt", CrystalDecisions.Shared.OpenReportMethod.OpenReportByTempCopy)
  For Each Module1.CRTable In CRReport.Database.Tables
    CRTLI = CRTable.LogOnInfo
    With CRTLI.ConnectionInfo
       .ServerName = "MyDSNName"
       .UserID = "MyUserName"
       .Password = "MyPassword"
       .DatabaseName = "MyDBName"
    End With
    CRTable.ApplyLogOnInfo(CRTLI)
  Next CRTable

Open in new window

http://bit.ly/18fN8yj
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:pascalmartin
ID: 40571860
Hi Guys,

The two codes are very similar, I tried David's code but still can't get my report open without asking for the DB login info.
On my development machine I entered my local DB info and the reports opens fine, after changing the DB info to the production server in the code behind, I published the website to the production server but then the report still ask for the DB login.
0
 

Author Comment

by:pascalmartin
ID: 40585678
Any possible solution for me....
0
 
LVL 4

Expert Comment

by:habibb
ID: 40845329
try to use below code:

private void LoadCrystalReports(string reportName)
        {


            ConnectionInfo myConnectionInfo = new ConnectionInfo();
            ReportDocument myReport = new ReportDocument();
            myReport.Load(Server.MapPath(reportName));
            // name of the crystal report

            Tables myTables = myReport.Database.Tables;

            foreach (CrystalDecisions.CrystalReports.Engine.Table myTable in myTables)
            {
                TableLogOnInfo myTableLogonInfo = myTable.LogOnInfo;
                myConnectionInfo.ServerName = "Servername"; //Your server
                // <SQL servername>
                myConnectionInfo.DatabaseName = ""; //Leave DB Blank
                // leave database name blank
                myConnectionInfo.UserID = "Username"; //Your User
                // username
                myConnectionInfo.Password = "Password"; //Your Users Password
                // password
                myTableLogonInfo.ConnectionInfo = myConnectionInfo;
                myTable.ApplyLogOnInfo(myTableLogonInfo);
            }

            Session["reportDocument"] = myReport;
            reportViewer.ReportSource = myReport;
            //reportViewer.RefreshReport();

        }

The difference above code has login info settings at each table level. Also try to use credentials code at below event:
protected void Page_Init(object sender, EventArgs e)



Report.discard
0
 

Author Comment

by:pascalmartin
ID: 40871750
I've requested that this question be deleted for the following reason:

No answer
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Learn how to automatically add page numbers in your next InDesign project. This can be very helpful in multi-page books and magazines that you are designing. Make sure your Pages window visible.:  In the document you wish to add page numbers to. Act…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question