vb.net connection


D

douglas

I am having a problem with a connection string. Right after the crystal
report opens, it asks me for connection information. This is happening since
I have windows authenication on my desktop (when running the vb.net
application) but I have sql server authenication only once The crystal report
is running. Thus can you tell me how to pass in the sql server authenication
once the crystal report opens up? Here is my code right now:
Dim cryRpt As New ReportDocument


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim cryRpt As New ReportDocument

Dim sql As String
Dim connetionString As String
Dim connection As SqlConnection
Dim connetionString2 As String
Dim connection2 As SqlConnection

Dim adapter As SqlDataAdapter
Dim ds As New DataSet

'located crystal report from
Dim strReportPath As String = "C:\test.rpt"

connetionString = "Data Source=server name,1433;Initial
Catalog=databasename;User ID=id;Password=sss"
connection = New SqlConnection(connetionString)

'sql = "select * from testtable
connection.Open()
adapter = New SqlDataAdapter(sql, connection)
adapter.Fill(ds)
connection.Close()
Try

For i = 0 To ds.Tables(0).Rows.Count - 1

'for get individual columns in a table
'dt = ds.Tables(0)
'For i = 0 To dt.Columns.Count - 1
' MsgBox(dt.Columns(i).ColumnName)
'Next

cryRpt.load(strReportPath)


Dim param1Fields As New
CrystalDecisions.Shared.ParameterFields

Dim param1Field As New CrystalDecisions.Shared.ParameterField
Dim param1Range As New
CrystalDecisions.Shared.ParameterDiscreteValue

Dim param2Field As New CrystalDecisions.Shared.ParameterField
Dim param2Range As New
CrystalDecisions.Shared.ParameterDiscreteValue

param1Field.ParameterFieldName = "@t1_id"
param2Field.ParameterFieldName = "@t2_id"

param1Range.Value = "xx"
param2Range.Value = "yy"

param1Field.CurrentValues.Add(param1Range)
param2Field.CurrentValues.Add(param1Range)

param1Fields.Add(param1Field)
param1Fields.Add(param2Field)

CrystalReportViewer1.ParameterFieldInfo = param1Fields 'to
pass parameter inf.to CRV
CrystalReportViewer1.ReportSource = cryRpt
CrystalReportViewer1.Refresh()


Next
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub

End Class
 
Ad

Advertisements

D

douglas

"Mr. Arnold":

I have a sql native client connection that the crystal report uses. The
crystal report
points to a stored procedure.
 
Ad

Advertisements

M

Michel Posseth [MCP]

Hello Douglas


Setup your connection string like this
"Provider=SQLNCLI;Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;"

This will run the connection in the user context ( so the user must have DB
rights )
another option would be to use mixed mode authentication , now setup a
crystal reports user with only rights on the used stored procedures IMHO
this is the safest way for deployable or web apps , in a trusted managed
environment you can go for built in security .


HTH

Michel Posseth
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top