[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Crystal Report asking for DB login

Posted on 2015-01-24
7
Medium Priority
?
408 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 84

Accepted Solution

by:
David Johnson, CD, MVP earned 2000 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
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 

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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

If I have to fix slow responding website my first thoughts are server side optimizations: the database may not be optimized or caching is not enabled, or things like that. We often overlook another major part of our web application: the client. We o…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
Suggested Courses

834 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