Click here to Skip to main content
14,698,276 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
When I run my project and look for the Crystal Report Viewer a Log in form was prompt before it loads the report. It is a database log in form... which i never set up. how can i remove it??

I use VB.NET 2010

I code this on a button

Dim sqlQuery As String = "SELECT * FROM security_log where Middle_Name= '" & TextBox1.Text & "'"
Dim sqlAdapter As New MySqlDataAdapter
Dim sqlcommand As New MySqlCommand
Dim ds As New DataSet
Dim cryRpt As New ReportDocument
       
Dim rptDoc As CrystalDecisions.CrystalReports.Engine.ReportDocument
rptDoc = New CrystalReport3
Form6.CrystalReportViewer1.ReportSource = rptDoc

With sqlcommand
   .CommandText = sqlQuery
   .Connection = sqlcon
End With

With sqlAdapter
   .SelectCommand = sqlcommand
   .Fill(ds, "security_log")
End With

ds.WriteXml("D:\secl.xml", XmlWriteMode.WriteSchema)
Form6.Show()


The form6 is where the Crystal Report viewer is..

Please help
Posted
Updated 9-Aug-20 22:20pm
v3

Hi if Crystal Report Send you the login form it's because he doesn't found the database credentials

TRY THIS


Private Sub AssignConnection(rpt As ReportDocument)
    Dim connection As New ConnectionInfo()


     connection.DatabaseName = "YourDataBaseName" 'myDataBase
    connection.ServerName = "YourServerAdress" '127.0.0.1
    connection.UserID = "UserID" 'root
    connection.Password = "Password" '12345



    ' First we assign the connection to all tables in the main report
    '
    For Each table As CrystalDecisions.CrystalReports.Engine.Table In rpt.Database.Tables
        AssignTableConnection(table, connection)
    Next

    ' Now loop through all the sections and its objects to do the same for the subreports
    '
    For Each section As CrystalDecisions.CrystalReports.Engine.Section In rpt.ReportDefinition.Sections
        ' In each section we need to loop through all the reporting objects
        For Each reportObject As CrystalDecisions.CrystalReports.Engine.ReportObject In section.ReportObjects
            If reportObject.Kind = ReportObjectKind.SubreportObject Then
                Dim subReport As SubreportObject = DirectCast(reportObject, SubreportObject)
                Dim subDocument As ReportDocument = subReport.OpenSubreport(subReport.SubreportName)

                For Each table As CrystalDecisions.CrystalReports.Engine.Table In subDocument.Database.Tables
                    AssignTableConnection(table, connection)
                Next

                subDocument.SetDatabaseLogon(connection.UserID, connection.Password, connection.ServerName, connection.DatabaseName)
            End If
        Next
    Next
    rpt.SetDatabaseLogon(connection.UserID, connection.Password, connection.ServerName, connection.DatabaseName)
End Sub


Private Sub AssignTableConnection(ByVal table As CrystalDecisions.CrystalReports.Engine.Table, ByVal connection As ConnectionInfo)
    ' Cache the logon info block
    Dim logOnInfo As TableLogOnInfo = table.LogOnInfo

    connection.Type = logOnInfo.ConnectionInfo.Type

    ' Set the connection
    logOnInfo.ConnectionInfo = connection

    ' Apply the connection to the table!

    table.LogOnInfo.ConnectionInfo.DatabaseName = connection.DatabaseName
    table.LogOnInfo.ConnectionInfo.ServerName = connection.ServerName
    table.LogOnInfo.ConnectionInfo.UserID = connection.UserID
    table.LogOnInfo.ConnectionInfo.Password = connection.Password
    table.LogOnInfo.ConnectionInfo.Type = connection.Type
    table.ApplyLogOnInfo(logOnInfo)
End Sub
   
v3
Comments
Member 9529406 30-Nov-13 20:11pm
   
Thank you for the reply....

The AssignTableConnection and ConnectionString on "SqlClient.ConnectionString" is gaving an error... it says that ConnectionString is not part of SqlClient and the AssignTableConnection is not declared....
Jean-Claude ADIBA 30-Nov-13 20:50pm
   
hi i have improve the next solution for you by adding AssignTableConnection implementation and i try to reorder your code i hope it's help


<pre lang="vb">
Dim sqlQuery As String = "SELECT * FROM security_log where Middle_Name= '" & TextBox1.Text & "'"
Dim sqlAdapter As New MySqlDataAdapter
Dim sqlcommand As New MySqlCommand
Dim ds As New DataSet
Dim cryRpt As New ReportDocument

Dim rptDoc As CrystalDecisions.CrystalReports.Engine.ReportDocument
rptDoc = New CrystalReport3

With sqlcommand
.CommandText = sqlQuery
.Connection = sqlcon
End With

With sqlAdapter
.SelectCommand = sqlcommand
.Fill(ds, "security_log")
End With

' in the AssignConnection i used System.Data.SqlClient.SqlConnectionStringBuilder(ConnectionString)
'to get the connection by providing the connectionstring in parameter
'BUT YOU MUST USE YOUR MYSQL CONNECTION sqlcon
AssignConnection(rptDoc)
rptDoc.SetDataSource(ds)

ds.WriteXml("D:\secl.xml", XmlWriteMode.WriteSchema)

'YOU MUST ALLWAYS PROVIDE CONNECTION INFO TO YOUR REPORTDOCUMENT BEFORE OPEN IT
Form6.CrystalReportViewer1.ReportSource = rptDoc
Form6.Show()

</pre>
Member 9529406 30-Nov-13 21:12pm
   
in the System.Data.SqlClient.SqlConnectionStringBuilder(ConnectionString) did you import it... i mean do you put it on the top.... i try to import it but the "AssignConnection()" is still on the underline(error) .. im sorry for the slow response coz im a newbie in vb.net2010.. itry not to put AssignConnection(rptDoc) but when i run it the DAtabase Login didn't appear but the report is empty...... im a little bit confuse now
Jean-Claude ADIBA 30-Nov-13 21:19pm
   
ok let's go slowly what SGBD do you use (MYSQL OR SQL SERVER)
Member 9529406 30-Nov-13 22:05pm
   
MYSQL
Jean-Claude ADIBA 30-Nov-13 22:36pm
   
OK Don't use this line System.Data.SqlClient.SqlConnectionStringBuilder(ConnectionString)
sqlclient is for sqlserver database

all you have to do is to remove this line form AssignConnection method
Dim con As New System.Data.SqlClient.SqlConnectionStringBuilder(YourConnectionString)

and provide your MYSQL DATABASE CONNECTION TO THE CRYSTAL REPORT ConnectionInfo Object
like this

connection.DatabaseName = "YourDataBaseName" 'myDataBase
connection.ServerName = "YourServerAdress" '127.0.0.1
connection.UserID = "UserID" 'root
connection.Password = "Password" '12345


Let's me know

i improve the assignconnection method
Member 9529406 30-Nov-13 23:23pm
   
It works! thank you very much!!!
Jean-Claude ADIBA 30-Nov-13 23:35pm
   
no matter ! so mark that your question has been solve by the solution 1 ! it remove your question to the unanswered questions liste ;)
mdgulam 21-Oct-14 7:21am
   
we have develop application in visual studio and attached crystal report. the issue is crystal reports open in all computer with the application. but in single machine only open database login dialog box. give me solution
Jean-Claude ADIBA 2-Nov-14 8:59am
   
Hi i hope you found a solution to your problem if not. do you try the solution i gave below with the AssignConnection(rpt As ReportDocument)
method ?
mdgulam 3-Nov-14 3:09am
   
thanks.

i have try all method but not get solution. but when format the system and re-install all the software now its working fine.
Kalpeshpatelbyk 15-Dec-16 16:30pm
   
Thanks a lot . u had got me out of this tricky situation god bless u.....
evry1falls 25-May-20 3:07am
   
Thank you for your solution.I just updated it to suit my scenario [I use DataTable, MS Access 2016] ->
Dim dt As DataTable = New DataTable()
Sub Form1_Load()
        Dim DataAdapter1 As New OleDbDataAdapter("SELECT * FROM TABLE_NAME", CN)
        DataAdapter1.Fill(dt)
        DataAdapter1.Dispose()
        CN.Close()
        cryRpt.Load(Application.StartupPath & "\CrystalReport1.rpt")
        AssignConnection(cryRpt)
        cryRpt.SetDataSource(dt)
        CrystalReportViewer1.ReportSource = cryRpt
End Sub
Nha Khoa Paris 10-Aug-20 3:22am
   
Someone who know short code that i can place in some long bio? Please show me how! thanks
Thanks you I need now. This code is very helpful
   
Comments
CHill60 10-Aug-20 4:21am
   
Please do not post comments as a "Solution" to a post. Use the "Have a Question or Comment?" link next to the post you want to comment on

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900