Crystal report Viewer keeps on Asking for Logon ID and Password at runtime - vb.net

Situation:
I made application using vb.net ,ms access and crystal report
When I run it my computer, I don't encounter any problem at all , but when I install and run it on other computer, crystal report asks for login ID and password
I have 2 tables in the report
The main report and the sub report
the Datasource for my rpt file is:
Datasource:C:\User\Documents\report.accdb
some suggests doing something like this:
myreport.SetDatabaseLogon.("user","password")
But I dont know how to use it and where to input the code
Anyone Familiar with this ? Thank you

I just wanted to provide you with the code that I used when I needed to connect to crystal reports embedded within my Visual Studio project.
Please disregard if you are not using the same method.
In my example, I connect to a SQL database so that the stored procedure my crystal report is using can be loaded.
I always used these subroutines to create a crystal report connection and configure the report with proper settings.
I'm not sure if you can set the connectioninfo with just a userID and password, but I figured this code might give you some ideas about what your code is missing.
If you need more help, please provide code snippets so we can help further diagnose.
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
'Crystal Report Here
Private mycrystalreport1 As CrystalReport1
Private Sub ConfigureCrystalReports()
Dim myConnectionInfo As ConnectionInfo = New ConnectionInfo()
mycrystalreport1 = New CrystalReport1()
Dim reportPath As String = Application.StartupPath & "\" & "CrystalReport1.rpt"
mycrystalreport1.Load(reportPath)
CrystalReportViewer1.ReportSource = mycrystalreport1
myConnectionInfo.ServerName = "SQL" 'OR WHATEVER SERVER NAME IS
myConnectionInfo.DatabaseName = "DATABASE_NAME"
myConnectionInfo.UserID = "USER_ID"
myConnectionInfo.Password = "PASSWORD"
SetDBLogonForReport(myConnectionInfo, mycrystalreport1)
End Sub
Private Sub SetDBLogonForReport(ByVal myConnectionInfo As ConnectionInfo, ByVal myReportDocument As ReportDocument)
Try
Dim myTables As Tables = myReportDocument.Database.Tables
For Each myTable As CrystalDecisions.CrystalReports.Engine.Table In myTables
Dim myTableLogonInfo As TableLogOnInfo = myTable.LogOnInfo
myTableLogonInfo.ConnectionInfo = myConnectionInfo
myTable.ApplyLogOnInfo(myTableLogonInfo)
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ConfigureCrystalReports()
'CAN SET PARAMETERS FOR A STORED PROCEDURE OR LOCAL VARIABLES IN CRYSTAL HERE
End Sub
Hopefully, this can provide you with some insight as to how crystal reports can take in a username and password.

Change your report to use ODBC. Makes it easier to check the database connection on each PC.
I'm guessing that the 2nd PC doesn't have the required database drivers to connect to accdb, but that's just a guess.

Related

Change connection string of access database in visual studio 2022

Ok so, basically i want to connect an access database (.mdb file) to my project. Now yes i have indeed connected it through the "data origin" wizard but the problem is that when i transfer the exe AND the database to another pc, it doesn't find it (obviously).
Dim appPath As String = My.Application.Info.DirectoryPath
Dim txtconnesione As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & appPath & "\Magazzino.mdb"
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.TableMagazzinoBindingSource.DataSource = txtconnesione
Me.TableMagazzinoTableAdapter.Fill(Me.MagazzinoDataSet.TableMagazzino)
End Sub
appPath is basically where the program gets started.
With this code it actually shows me the whole grid but it's empty, just like this:
i didn't used a connection string and i didn't copy it in the project (sorry for bad english, if you don't understand i'll try to explain better)

How can i store file name and file path to the database in DataGridview?

i am trying to store file name and file path to the database by opening a OpenFileDiologue. here my codes.
NOTE: DB is already connected. properly showing data on datagridview and database is created with ms access named database1.accdb.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim showdialog1 As New OpenFileDialog
showdialog1.Filter = "Supported Video Files. | *.mp4; *.avi; *.wmv; *.mpg; *.mpeg; *.mov; *.webm; *.flv; *.mkv"
showdialog1.Title = "Add Supported Video Files."
If showdialog1.ShowDialog = System.Windows.Forms.DialogResult.OK Then
AxWindowsMediaPlayer1.URL = showdialog1.FileName
Else
Exit Sub
End If
End Sub
here is a pic of my design. this will help you to understand me.
Click to View the pic
help me to store file name and file path to the database. hope i will get the easiest method.
It's simple :
Public sub Button1_Click
'your connection string
connection.open
Dim cmd as new Oledbcommand("Insert into
[tablename](columnname) values (#mycolumn)",yourconnectionstringname)
If openfiledialog1.dialogresult=dialogresult.ok then
cmd.parametres.add("#mycolumn",sqldbtype.varchar).value=openfiledialog1.filename
cmd.executenonquery()
connection.close
I hope this would help to achieve your goal

VB.NET 2008 - Input to data to website controls and download results

this is my first Q on this website so let me know if I have missed any important details, and thanks in advance.
I have been asked to access a website and download the results from a user-inputted form. The website asks for a username/password and once accepted, several questions which are used to generate several answers.
Since I am unfamiliar with this area I have set up a simple windows form to tinker around with websites and try to pick things up. I have used a webbrowser control and a button to use it to view the website in question.
When I try to view the website through the control, I just get script errors and nothing loads up. I am guessing I am missing certain plug-ins on my form that IE can handle without errors. Is there anyway I can identify what these are and figure out what to do next? I am stumped.
The script errors are:
"Expected identifier, string or number" and
"The value of the property 'setsection' is null or undefined"
Both ask if I want to continue running scripts on the page. But it works in IE and I cannot see why my control is so different. It actually request a username and password which works fine, it is the next step that errors.
I can provide screenies or an extract from the website source html if needed.
Thanks,
Fwiw my code is:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'WebBrowser1.ScriptErrorsSuppressed = True
WebBrowser1.Navigate("http://website.com")
'WebBrowser1.Navigate("http://www.google.com")
End Sub
Thanks for Noseratio I have managed to get somewhere with this.
Even though the errors I was getting seemed to be related to some XML/Java/Whatever functionality going askew it was actually because my webbrowser control was using ie 7.0
I forced it into using ie 9 and all is now well. So, using my above example I basically did something like this:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'WebBrowser1.ScriptErrorsSuppressed = True
BrowserUpdate()
WebBrowser1.Navigate("http://website.com")
'WebBrowser1.Navigate("http://www.google.com")
End Sub
Sub BrowserUpdate()
Try
Dim IEVAlue As String = 9000 ' can be: 9999 , 9000, 8888, 8000, 7000
Dim targetApplication As String = Process.GetCurrentProcess.ToString & ".exe"
Dim localMachine As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine
Dim parentKeyLocation As String = "SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl"
Dim keyName As String = "FEATURE_BROWSER_EMULATION"
Dim subKey As Microsoft.Win32.RegistryKey = localMachine.CreateSubKey(parentKeyLocation & "\" & keyName)
subKey.SetValue(targetApplication, IEVAlue, Microsoft.Win32.RegistryValueKind.DWord)
Catch ex As Exception
'Blah blah here
End Try
End Sub

How to generate a new MS access file programmatically

I have looked far and wide, in the deepest darkest corners of the internet, but for the life of me, I can not find the correct way to open a NEW Access file and then using vb.net to write data in the database..
The keywords here are NEW database, I don't want to open an existing file.
Is this even possible?
Thanks in advance!
I have finally found the way, thanks to a co-worker of mine
Neither ADO.NET nor ActiveX Data Object (ADO) provides the means to create Microsoft
Access Database. However, we can create Access databases by using the Microsoft Jet OLE DB
Provider and Microsoft ADO Ext. 2.7 for DDL and Security (ADOX) with the COM Interop
layer. To do so, select References from the Project Menu, choose the COM tab, and add a
reference to Microsoft ADO Ext. 2.7 for DDL and Security; then you can use this function.
When you have done this, use the following snippet to create a database
Public Class Form1
Private Sub btnLoad_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnLoad.Click
CreateAccessDatabase("C:\test\testDB.mdb")
MsgBox("Database created")
End Sub
Public Function CreateAccessDatabase( ByVal DatabaseFullPath As String) As Boolean
Dim bAns As Boolean
Dim cat As New ADOX.Catalog()
Try
Dim sCreateString As String
sCreateString =_
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
DatabaseFullPath
cat.Create(sCreateString)
bAns = True
Catch Excep As System.Runtime.InteropServices.COMException
bAns = False
Finally
cat = Nothing
End Try
Return bAns
End Function
End Class

Crystal Report always asks for database login

I need your help.
I'm writing code for a shop program and I am using vb.net 2008 with Crystal Report version 10.5.37xxxx
The problem is when I'm trying to install my program on the client computer, everything works but not in my Crystal Report. It always asks for the database login and I did not code my program to ask for the database login.
I just wrote it in simple code like this:
Public Class Form16
Private Sub Form16_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim view As New CrystalReport4
view.SetParameterValue("p_1", Form5.no_faktur_tb_immanuel)
CrystalReportViewer1.ReportSource = view
End Sub
End Class
Can anyone help me with this?
You should be able to manually code the login credentials.
Public Class Form16
Private Sub Form16_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim view As New CrystalReport4
Dim user as string = "Username"
Dim pwd as string = "Password"
view.SetDatabaseLogon(user, pwd)
view.SetParameterValue("p_1", Form5.no_faktur_tb_immanuel)
CrystalReportViewer1.ReportSource = view
End Sub
End Class
Make Sure your Report DataSource Provider is set to Microsoft OLE DB provider for SQL Server and not SQL Server Native Client 10.0
try that open field explorer---> database field --->Right Click -->current Data source --->reports connection----->report ----->property ---->
set Property as---
Data Source: .\Databasename.accdb
and code on viewer form load as
Dim cryRpt As New ReportDocument
Dim Report1 As New rptItemWise
Dim strServerName As String
strServerName = Application.StartupPath
rptItemWise.SetDatabaseLogon("admin", "", strServerName, "dastabasename.accdb", True)
cryRpt.Load(Application.StartupPath + "\rptItemWise.rpt")
also change the report connection same as data source
i think that code work for you ....
This will work for you!
C# Code :
ConnectionInfo boconnectioninfo = new ConnectionInfo ();
boconnectioninfo.ServerName= "D-2818-w2k";
boconnectioninfo.DatabaseName ="NW";
boconnectioninfo.UserID ="sa";
boconnectioninfo.Password ="sa";
CrystalReportViewer1 .ReportSource = Server.MapPath("CrystalReport1.rpt");
TableLogOnInfos botableInfo= CrystalReportViewer1 .LogOnInfo;
foreach (TableLogOnInfo obj2 in botableInfo)
{
obj2.ConnectionInfo =boconnectioninfo;
}
Vb.net Code :
Dim boconnectioninfo As New ConnectionInfo
boconnectioninfo.ServerName = "sa"
boconnectioninfo.DatabaseName = "sa"
boconnectioninfo.UserID = "sa"
boconnectioninfo.Password = "sa"
Me.rptViewer.ReportSource = _ReportPath
Me.rptViewer.SelectionFormula = _SelectionFormula
If Not _ParameterFields Is Nothing Then
Me.rptViewer.ParameterFieldInfo = _ParameterFields
End If
Dim a As TableLogOnInfos = Me.rptViewer.LogOnInfo
' Iterate through the list.
For Each aa As TableLogOnInfo In a
aa.ConnectionInfo = boconnectioninfo
Next
Me.Cursor = Cursors.Default
rptViewer.Refresh()