Crystal Reports failed to open the connection - vb.net

I am developing a desktop software which is creating proposals and invoices. I am storing my database (MySql) in a remote server. Everything is working perfectly fine in my PC which i am using for coding.
On client machine I can add,update and delete records without any problem. But when i try to open a record in then I am facing with an error below.
I was created the report in VB.NET but when I face with the error than I opened the rpt file in Crystal Reports XI Release 2 and updated data source location, verified database and save the file. Some part of my code is :
ElseIf Me.Text = "Tekliflere Gözat" Then
Form16.Text = "Teklif Detayları:"
Dim strReportPath As String
Dim rptDoc As CrystalDecisions.CrystalReports.Engine.ReportDocument
strReportPath = My.Application.Info.DirectoryPath & "\Teklif.rpt"
rptDoc = New ReportDocument
rptDoc.Load(strReportPath)
rptDoc.SetDatabaseLogon("USER_NAME", "PASSWORD", "SERVER_IP", "DB_NAME")
Form16.CrystalReportViewer1.ReportSource = rptDoc
Form16.CrystalReportViewer1.SelectionFormula = "{teklif1.teklifno} =" & ListView1.SelectedItems(0).Text
Form16.CrystalReportViewer1.Refresh()
Form16.CrystalReportViewer1.RefreshReport()
Form16.Show()
Me.Close()
Could you please advise.
Thank you.
Regards
Oguz

I've found the solution. But first have to look at the casue. While connecting to a remote database via my software everthing is working fine. But when I was designing a report in CR, I created a connection in database expert menu. So that means locally I am describing to CR that where and how to connect. But when I install my software with all necessery components to the client machine CR report files searching the connection criteria and as a matter of course it can not find it in client machine.
So the solution is to install Mysql ODBC Connector to the client machine and configure it with the same settings in my PC. Or as an alternative solution, define all connection and database settings programatically in your code.
Hope this helps.

Related

dBaseIV file creation from SQL Server 2016 database

I have a requirement as follows: on click of a link button on a web page, I have to fetch some records from a SQL Server 2016 database and convert them into dBaseIV format (.env, .ad1, .ad2, .veh) files and show a download/save as popup on the page where the end user would be able to download the files individually.
Any leads would be appreciated.
dBaseIV files expected on click of link button
This is like 90's requirement - a lot from memory ...
This is a VS 2017 console app ..., creates a DBaseIV file called bill and inserts a record, of course the logic to create, read etc is not included - also
System.IO.File.Exists is of dubious reliability on 64bit systems - someone else might have a better solution
I don't use IIS - so no idea on how to setup downloads there
and - I ran this on a Dell Windows 10 machine, the dBaseIV driver existed in ODBC
Module Module1
Sub Main()
Dim connectionString As String = "Driver={Microsoft dBase Driver (*.dbf)};DBQ=C:\temp\"
Using cn As New Odbc.OdbcConnection(connectionString)
cn.Open()
If Not System.IO.File.Exists("C:\Temp\books.dbf") Then
Using cmd As New Odbc.OdbcCommand("CREATE TABLE BOOKS (title char(50))", cn)
cmd.ExecuteNonQuery()
End Using
End If
Using cmd As New Odbc.OdbcCommand("INSERT INTO BOOKS (title) VALUES('The Story of Bill')", cn)
cmd.ExecuteNonQuery()
End Using
cn.Close()
End Using
Console.Write("done")
Console.ReadKey()
End Sub
End Module

Vb.Net preview report from access database

I am using visual studio 2010 to develop my desktop application and ms access database. I have already designed reports in access database and they are working perfectly. Now my concern is that is it possible to use these access reports in my Vb.Net application?
I need this because it would be much easier to distribute the software instead of using crystal report where I will need to install a run time machine for crystal reports.
It's possible to do but it's a horrible implementation. You basically have to launch Access, open the database file in Access, then navigate down and launch the report. There is no way to just "view" the report inside your app. It will only show inside Access.
I think your best option is to use ReportViewer control if you don't want to use Crystal Reports.
I found this: https://support.microsoft.com/kb/317113?wa=wsignin1.0
To preview or to print an Access report, you call the OpenReport method of the DoCmd object. When you call OpenReport, one of the arguments that you pass determines whether the report is previewed on the screen, or whether it is sent to the printer:
' Preview a report named Sales:
oAccess.DoCmd.OpenReport(ReportName:="Sales", View:=Access.AcView.acViewPreview)
' Print a report named Sales:
oAccess.DoCmd.OpenReport(ReportName:="Sales", View:=Access.AcView.acViewNormal)
But I haven't been able to find much info/help regarding OpenReport method or DoCmd object.
I am not a proffesional developer, but after long research it's worked for my project.
I would like to open directly from MS Access, my existing reports and then to open these from not default installation folder path (different for each one pc). The third requirement was to open more than one report (Not all together).
Design:
Form8.vb [Design]
vb.Net Code:
Imports System.ComponentModel
Imports Microsoft.Office.Interop.Access
Public Class Form8
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim oAccess As New Microsoft.Office.Interop.Access.Application()
Dim CurDir As String = System.AppDomain.CurrentDomain.BaseDirectory
Dim FPath As String = CurDir & "\YourDatabase.accdb"
oAccess.Visible = True
oAccess.OpenCurrentDatabase(FPath)
If ComboBox1.Text = "Your text" Then
oAccess.DoCmd.OpenReport(ReportName:="Your Report Name", View:=AcView.acViewPreview)
ElseIf ComboBox1.Text = "Your text2" Then
oAccess.DoCmd.OpenReport(ReportName:="Your Report Name", View:=AcView.acViewPreview)
ElseIf ComboBox1.Text = "Your text3" Then
oAccess.DoCmd.OpenReport(ReportName:="Your Report Name", View:=AcView.acViewPreview)
End If
End Sub
End Class
Replace YourDatabase with YourDatabaseName, Replace Your text,Your text1,Your text2,Your text3 with YourText, Replace Your Report Name with the Name of your report Name, As needed.
Finally, in order for this solution to work, you need:
1) Your (Conn.open) connection to look like this:
Dim dbsource As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source = |DataDirectory|\Your DB.accdb"
2) In Solution Explorer, Your database to include in your project or to your setup project, to be installed with your project. like this:
Solution Explorer [image]
SetUp Project link
3) At server explorer, Data Connection the (Sourse) Database file name, must be with the full path name e.g like this:
C:\Users\User\Desktop\YourDatabase.accdb, and the connection String at the Properties like this:
Provider=Microsoft.ACE.OLEDB.12.0;Data Source = "C:\Users\User\Desktop\YourDatabase.accdb".
I hope this helps!!!
The following code:
Preview a report named Sales:
oAccess.DoCmd.OpenReport(ReportName:="Sales", View:=Access.AcView.acViewPreview)
Print a report named Sales:
oAccess.DoCmd.OpenReport(ReportName:="Sales", View:=Access.AcView.acViewNormal)
But I haven't been able to find much info/help regarding OpenReport method or DoCmd object.
This will only work if you are using VB.Net to automate the Access application. This will open the Access application and allow you to view or print the reports just as if you were running Access directly. However, you need to have the Access application (not just the .mdb or .accdb file) on the computer that is running the VB.Net application.
I have not found any way to utilize the Access reports without having Access on the computers running the VB.Net application. I'm looking into using Crystal Reports for the application I'm working on now.

Error while uploading Excel data to SQL server 2005

I have a requirement to upload excel data into a SQL Server 2005 table. Initially I copied Excel data to a temp table and based on condition I have updated and inserted records into the SQL Server table.
Everything works fine in my local system. Same program I moved to quality server there I faced this error
The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.
Then we installed 'Microsoft.ACE.OLEDB.12.0 provider on quality server. Now this error appearing
The Microsoft Office Access database engine cannot open or write to the file ''. It is already opened exclusively by another user, or you need permission to view and write its data."
Kindly help me out to solve this issue.
SqlConnection con = new SqlConnection();
con = SQLManager.openSQLConnection();
string path = FileUpload1.PostedFile.FileName;
string excelConnectionString = #"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0 Xml;Persist Security Info=False";
//Create Connection to Excel work book
OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
OleDbCommand cmd = new OleDbCommand("Select [CM_CODE],[CM_NAME],[CM_ADD1],[CM_ADD2],[CM_ADD3],[CM_ADD4],[CM_CITY],[CM_PHONE],[CM_CG_CODE],[CM_CO_CODE],[CM_EXPIRY_DATE],[CM_PINCODE],[CM_EMAIL] from [Sheet1$]", excelConnection);
excelConnection.Open();
OleDbDataReader dReader;
dReader = cmd.ExecuteReader();
Regards,
Sathya
This is most likely a file permissions issue. Does the account that the program runs under have folder level permission to read files from the file location.
Find out which account the program runs under and then add appropriate access permissions to the folder where you upload your excel files.
If it's IIS then whichever account your app pool runs under needs write access to the folder that you upload to. Permissions can usually only be set by web server admin.
Wing
Finally i found out the solution.
I have created one folder under my application folder in Quality server.
Uploaded excel sheets wil get stored under this new folder.
and that path i am referring while updating my SQL server database.
Everything works fine now...
Thank u all for your support
Regards,
Sathya

I want my vb.net program with sqldb to be transferable

I'm having trouble with my vb.net program. It has a database with a SqlConnection string of:
DbConn = New SqlConnection("Data Source=ACE-DUO;Initial Catalog=db_CVSO;Persist Security Info=True;User ID=sa;Password=pwd")
I made an installer for this vb.net program but I'm having problems regarding my SQL Server connection string. It's because once I installed the program in different computer. The server name in my case (ACE-DUO) changes and the database itself cannot be located.
I know how to detach the file and attach it to vb.net program. what I'm really aiming for is that I want the connection string to change on based where the program resources were placed.
For example, if the program was installed in the C:\Program Files\MyDatabase folder, I want to make it as a part of the connection string so it would be opened in different computer.
If you don't need multiple shared access to your database you could take advandage of the LocalDB feature of Sql Server 2012.
You connection string could be changed to
DbConn = New SqlConnection("Server=(localdb)\v11.0;Integrated " & _
"Security=true;AttachDbFileName=C:\Program Files\MyDatabase\db.mdf;"
Article on LocalDB

Crystal Reports prompts login only on other PC

I made a small VB.NET application which includes a Crystal Report. Running the Crystal Report on the machine I made it works perfectly. When I run the application on my laptop, the Crystal Report always prompts me for a login eventhough the database has no login set to it. I have tried passing in "Admin" and "" with code, but no luck.
I'm working with an Access database, this is the code I have to load my Crystal Report:
If frmReport Is Nothing OrElse frmReport.IsDisposed Then
frmReport = New frmReport
End If
frmReport.CrystalReportViewer1.ReportSource = "../../Reports/Klantenbeheer.rpt"
frmReport.MdiParent = Me
frmReport.Show()
I did look at Prevent login of ODBC Text driver in Crystal Report for Visual Studio 2010 but I'm not sure if it applies to my situation?
I also tried setting the rpt's datasource to the datasource I work with in the application and then assigning that to the ReportSource, but no luck either.
Some people found a solution in changing from DAO to OLEDB, but I have used OLEDB from the beginning.
Perhaps the code found in at the bottom of this thread could help you? Specifically:
Imports CrystalDecisions.Shared
Imports CrystalDecisions.CrystalReports.Engine
Dim myConnectionInfo As ConnectionInfo = New ConnectionInfo()
Dim myReport As New ReportDocument()
myReport.Load(Server.MapPath("ReportName")) 'name of your Crystal Report - see note below
Dim myTables As Tables = myReport.Database.Tables
For Each myTable As CrystalDecisions.CrystalReports.Engine.Table In myTables
Dim myTableLogonInfo As TableLogOnInfo = myTable.LogOnInfo
myConnectionInfo.ServerName = <SQL servername>
myConnectionInfo.DatabaseName = "" 'leave database name blank
myConnectionInfo.UserID = 'login name
myConnectionInfo.Password = 'password
myTableLogonInfo.ConnectionInfo = myConnectionInfo
myTable.ApplyLogOnInfo(myTableLogonInfo)
Next
CrystalReportViewer1.ReportSource = myReport
It is made for ASP.Net, but might work with minor adjustments?
Well, I know it's an old question. But I think I should just add an info that, I got a link that, after painful research, he tell that, we must copy the correct version of crdb_ado.dll. Read it here : XtremeNetTalk. Unfortunately, I haven't been able to locate that file yet in the internet! I hope I can complete this answer with this.