Solved

Crystal Report asking for DB login

Posted on 2015-01-24
7
159 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 79

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Have you ever wanted to create graphical elements directly in inDesign? This tutorial will teach you how to have an image bound within text using the pathfinder tool in inDesign CS6. This technique will help decrease the amount of time spent opening…
Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
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…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

770 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