Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
VB

HI there
I have been trying to connection my data with crystal report, My connection string is working fine.

My Question is : Am I missing something strange ? any line of code or any word which should make my code to run.

I am not sure about this line
rpt.DataSourceConnections.Item(0).SetLogon("admin", "")
whether admin is correct, OR is this line is correct ?


I got an error when I run crystal report :
CSS
Failed to load database information.
Error in File temp_56590165-ed16-4da1-a673-53bddf012e93 {1BF41BB8-7C9E-4319-AAE9-A637C86EE90D}.rpt:
Failed to load database information.


PLEASE HELP ME TO SOLVED THIS TROUBLE

Click here for Reference Images : Images in Dropbox

Here is my code :
VB.NET
Imports System.Data.OleDb
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

Public Class Form5

    Dim rpt As New CrystalReport1

    Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

	createconn()'Create connection with DB
        Cmd.CommandText = "SELECT * FROM products"
        Cmd.Connection = Conn

        Dim adp As New OleDbDataAdapter
        adp.SelectCommand = Cmd
        Dim ds As New DataSet
        adp.Fill(ds, "products")

        Try
            rpt.DataSourceConnections.Item(0).SetConnection("", DBPath, False)
            rpt.DataSourceConnections.Item(0).SetLogon("admin", "")

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        rpt.SetDataSource(ds.Tables(0))' Getting Error at this stage
        cr.ReportSource = rpt
    End Sub
End Class

'Module for connection

Imports System.Data.OleDb

Module mdlconn
    Public Conn As New OleDbConnection
    Public Cmd As New OleDbCommand
    Public DBPath As String = Environment.CurrentDirectory & "\data\db.mdb;"
    Function createconn()
        Try

            If Conn.State = ConnectionState.Open Then Conn.Close()
            Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " _
            & Environment.CurrentDirectory & "\data\db.mdb;"
            Conn.Open()
            Return True
        Catch ex As Exception
            MsgBox("Unable to create connection." + vbCrLf + "Err : " + ex.Message, vbCritical)
            Return False
            End
        End Try
    End Function

End Module
Posted
Updated 4-Jul-14 19:33pm
v2

1 solution

 
Share this answer
 

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