Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello coders, I have developed a project in VB.Net and SQL Server and after creating a setup of the project and installed on the client's PC, the CRUD operations are working just fine but crystal report shows an error that the database cannot be found due to wrong path which is like "D:\myproject\bin\Debug cannot be found.
Since the CRUD operations and reporting are working fine on my PC but reporting is not working on clients' PC.
I am using the following code for displaying the crystal report:
Form1.loaditems()
       Dim ds As New DataSet4
       Dim ad As New DataSet4TableAdapters.proceduresTableAdapter
       ad.Fill(ds.procedures)
       Dim rpt As New CrystalReport4
       rpt.SetDataSource(ds)
       CrystalReportViewer1.ReportSource = rpt


For connecting VB.Net to SQL Server, I am using the following code
Imports System.Data
Imports System.Data.SqlClient
imports system.IO
Module connection
    Public dbconn As SqlConnection
    Public amountPaid As Integer = 0
    Sub connectDatabase()
        Try
            dbconn = New SqlConnection("server=(localdb)\MSSQLLocalDB;AttachDbFileName=" & System.IO.Path.GetFullPath("DatabaseName.mdf") & ";Integrated Security=True;")
            dbconn.Open()
        Catch ex As Exception
            MsgBox(ex.Message.ToString)
        End Try
    End Sub
End Module


I think I need some way to connect the dataset with the table like
System.IO.Path.GetFullPath("DatabaseName.mdf")
and not the actual path but I don't know how to do that.
You all are requested if anyone has a solution to this problem, I shall be very thankful.
Thank you

What I have tried:

For connecting VB.Net to SQL Server, I am using the following code
<pre>Imports System.Data
Imports System.Data.SqlClient
imports system.IO
Module connection
    Public dbconn As SqlConnection
    Public amountPaid As Integer = 0
    Sub connectDatabase()
        Try
            dbconn = New SqlConnection("server=(localdb)\MSSQLLocalDB;AttachDbFileName=" & System.IO.Path.GetFullPath("DatabaseName.mdf") & ";Integrated Security=True;")
            dbconn.Open()
        Catch ex As Exception
            MsgBox(ex.Message.ToString)
        End Try
    End Sub
End Module


and for displaying records on crystal report I am using the following code
Form1.loaditems()
       Dim ds As New DataSet4
       Dim ad As New DataSet4TableAdapters.proceduresTableAdapter
       ad.Fill(ds.procedures)
       Dim rpt As New CrystalReport4
       rpt.SetDataSource(ds)
       CrystalReportViewer1.ReportSource = rpt
Posted
Comments
[no name] 19-Apr-23 14:55pm    
If your vb code is filling datasets for CR, CR doesn't need a connection; it's your "vb code" that's using a "debug" (exe) path.
sarfarazbhat 21-Apr-23 6:11am    
Gerry Schmitz, thank you so much for showing me the right way. The problem got solved. Thank you once again.
[no name] 21-Apr-23 12:38pm    
You're welcome!

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