Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
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

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
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 21:20pm
v3

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

TRY THIS


VB
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
 
Share this answer
 
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
Thanks you I need now. This code is very helpful
 
Share this answer
 
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