Crystal Report always asks for database login - vb.net

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()

Related

VB.Net Public Property Return Blank Value

I'm New in Programming, i can't identify some bugs/error if the Application doesn't tell me where's the error is. So the case is i Code Public Property in purpose to show Text (ID) from FormLogin TextBox into A Lable in another form (FormInputTimeSheet) to Retrieve some data from SQL Server by referring to the ID (i'm using word NIK for ID).
In FromLogin
Dim FIT As New FormInputTimeSheet
FIT.NIKLookup2 = FlTbNIK.Text
Me.Hide()
FormInputTimeSheet.Show()
MessageBox.Show("Login Success! Selamat Datang " & table.Rows(0)(1).ToString())
FlTbNIK is the TextBox i'm using to type ID for Login
In FormInputTimeSheet
Public Property NIKLookup2 As String
Private Sub FormInputTimeSheet_Load(sender As Object, e As EventArgs) Handles MyBase.Load
FiLbNIK.Text = NIKLookup2
End Sub
FiLbNIK is the target Label and the result is Blank on the Label FiLbNIK
but in the same project i'm using same procedure but it worked, it is successed to show the ID from TextBox in FormLogin to Label in FormEditPassword, here is the code
In FormLogin
Dim FEP As New FormEditPassword
FEP.NIKLookup1 = FlTbNIK.Text
FEP.NameLookup = FlLbName.Text
Me.Hide()
FEP.Show()
In FormEditPassword
Public Property NIKLookup1 As String
Public Property NameLookup As String
Private Sub FormEditPassword_Load(sender As Object, e As EventArgs) Handles MyBase.Load
FeLbEpHlp.Visible = False
FeLbNIK.Text = NIKLookup1
FeLbName.Text = NameLookup
End Sub
These Codes Worked and Showed the ID & Name.
Any Solution would be Appriciated.
Thank before.
As what Steve Had Answered from the comment, the error has been Solved by Changing
Dim FIT As New FormInputTimeSheet
FIT.NIKLookup2 = FlTbNIK.Text
Me.Hide()
***FormInputTimeSheet.Show()***
MessageBox.Show("Login Success! Selamat Datang " & table.Rows(0)(1).ToString())
To
Dim FIT As New FormInputTimeSheet
FIT.NIKLookup2 = FlTbNIK.Text
Me.Hide()
***FIT.Show()***
MessageBox.Show("Login Success! Selamat Datang " & table.Rows(0)(1).ToString())
Thanks Steve!

Crystal report Viewer keeps on Asking for Logon ID and Password at runtime

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.

Writing multiple SQL server tables as separate nodes to XML Document

I have multiple SQL server tables from which I want to pull data and write to XML. I want my XML to be formed like this:
<Data>
<Query1Table>
<Table>
<Column1>Data</Column1>
<Column2>Data</Column2>
...
</Table>
</Query1Table>
<Query2Table>
<Table>
<Column1>Data</Column1>
<Column2>Data</Column2>
...
</Table>
</Query2Table>
</Data>
I'm using datasets to write the xml, but the code I'm working with doesn't append the data, it overwrites:
Dim connetionString As String
Dim connection As SqlConnection
Dim adapter As SqlDataAdapter
Dim directory As String
Dim ds As New DataSet
Dim sql As String
connection = New SqlConnection(connetionString)
sql = "select * from scheduledata"
connection.Open()
adapter = New SqlDataAdapter(sql, connection)
adapter.Fill(ds)
ds.DataSetName = "Schedule"
ds.WriteXml(directory)
ds.Clear()
sql = "select * from costdata"
adapter = New SqlDataAdapter(sql, connection)
adapter.Fill(ds)
ds.WriteXml(directory)
I have tried adding it all to the same data set by calling the SQL queries at once, but that doesn't help to separate them in the XML -- it groups them in the same node.
I'm open to a different method if anyone has a good suggestion.
You've defined directory as a string, so ds.WriteXml will (create and) write to a file by that name.
Use a FileStream or XmlTextWriter instead.
The way that I write to .xml files (which works) is as follows
Private Sub AuthenticationContinuebtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AuthenticationContinuebtn.Click
On Error GoTo PasswordHandler
GlobalVariables.Username = Usernametxtbx.Text
GlobalVariables.Password = Passwordtxtbx.Text
GetUsernamePassword()
Close()
Exit Sub
PasswordHandler:
MsgBox("Incorrect password or username.")
End Sub
Private Sub UserAuthenticationWindow_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim FileName4 As String = "C:\Forte\UsernamePassword.xml"
Dim FileRead4 As XmlTextReader = New XmlTextReader("C:\Forte\UsernamePassword.xml")
'If statement to see if file exists.
If System.IO.File.Exists(FileName4) = True Then
Do While (FileRead4.Read)
Select Case FileRead4.NodeType
Case XmlNodeType.Text, XmlNodeType.Element
If FileRead4.Name = "Username" Then
FileRead4.Read()
Usernametxtbx.Text = FileRead4.Value
GlobalVariables.Username = Usernametxtbx.Text
End If
If FileRead4.Name = "Password" Then
FileRead4.Read()
Passwordtxtbx.Text = FileRead4.Value
GlobalVariables.Password = Passwordtxtbx.Text
End If
End Select
Loop
Else
MainBox.MainTextBox.AppendText(FileName4 & " could not be found. Settings are restored to defaults.")
MainBox.Logging(Date.Now & FileName4 & " could not be found. Settings are restored to defaults.")
End If
FileRead4.Close()
End Sub
Public Sub createNode3(ByVal Username As String, ByVal Password As String, ByVal writer As XmlTextWriter)
'On Error Resume Next
writer.WriteStartElement("Username_Password")
writer.WriteStartElement("Username")
writer.WriteString(Username)
writer.WriteEndElement()
writer.WriteStartElement("Password")
writer.WriteString(Password)
writer.WriteEndElement()
writer.WriteEndElement()
End Sub

How to manipulate the SQL Server database from grid view (Form Application in VB.NET)

I need to control a database from grid view.
In another article I have to see how to manipulate a database, but there still used textbox and button for next process. In my case I need to control the data from grid view, so tell me please if you have solution for this problem.
Specifications:
application form
visual basic .NET 2010
SQL Server database
A quick search online found this: link. Below is the example code from that link showing how to display data.
If you want to do CRUD, please take a look at the Microsoft example here.
Imports System.Data.OleDb
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="Your .mdb path";"
Dim sql As String = "SELECT * FROM Authors"
Dim connection As New OleDbConnection(connectionString)
Dim dataadapter As New OleDbDataAdapter(sql, connection)
Dim ds As New DataSet()
connection.Open()
dataadapter.Fill(ds, "Authors_table")
connection.Close()
DataGridView1.DataSource = ds
DataGridView1.DataMember = "Authors_table"
End Sub
End Class

Visual Studio Embedded Crystal Report Keeps Prompting Database Login?

I'm using visual studio 2005 to develop a form with a combobox passing a value into the parameter of an embedded crystal report. I'm trying to figure out why it keeps prompting me for a database login every single time you try to run the report with a different combobox selection.
Here is my code:
private Sub Form1_load...
Dim ConnName As String
Dim ServerName As String
Dim DBName As String
Dim user As String
Dim pass As String
Dim gDBA As ADODB.Connection
Dim records As ADODB.Recordset
Dim datver As ADODB.Recordset
Dim query As String
'---OPEN THE DATABASE CONNECTIONS
gDBA = New ADODB.Connection ': gDBA.CursorLocation = adUseServer
'Added to prevent time out error
gDBA.CommandTimeout = 1000 : gDBA.ConnectionTimeout = 1000
gDBA.ConnectionString = "Server=svr13;Database=subscribers;User ID=KViews;Password=Solution;Trusted_Connection=True;"
gDBA.Open("Data Source=Kaseya;Initial Catalog=subscribers;User Id=KViews;Password=Solution;", "KViews", "Solution")
records = New ADODB.Recordset
query = "select distinct groupname from _v_k order by groupname desc"
'records.ActiveConnection = gDBA.ConnectionString
records.CursorType = CursorTypeEnum.adOpenForwardOnly
records.LockType = LockTypeEnum.adLockReadOnly
records.Open(query, gDBA)
Do While Not records.EOF
ComboBox1.Items.Add(records.Fields("groupname").Value)
records.MoveNext()
Loop
end Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim selected As String
selected = ComboBox1.Text
Dim cryRpt As New ReportDocument
cryRpt.Load("C:\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplication1\CrystalReport1.rpt")
cryRpt.SetDatabaseLogon("KViews", "Solutions", "svr13", "subscribers")
cryRpt.SetParameterValue("companyname", selected)
CrystalReportViewer1.ReportSource = cryRpt
CrystalReportViewer1.Refresh()
End Sub
I looked at this previous posting database login prompt with crystal reports
but this wasn't very helpful. I couldn't find where a CMC was to disable the prompt.
Any ideas? thanks in advance
figured it out. the following line was incorrect
cryRpt.SetDatabaseLogon("KViews", "Solutions", "svr13", "subscribers")
it should just be this:
cryRpt.SetDatabaseLogon("KViews", "Solutions")
the login prompt doesn't show up anymore.