Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to connect to Sql Server

Status
Not open for further replies.

SidTheSquid

Programmer
Sep 25, 2002
34
0
0
CA
Something so simple yet...
I am new to crystal reports and vb.net (and plain old vb)

I managed to create a crystal report and it is displayed on a webform using the crystal report viewer. This report is now to accept parameters from user input, I've discovered how to recieve the parameters and add them to the report viewer parameter fields, and bind it all together.

The part that I am stuck on is trying to connect to the sql server from my vb code-behind pages in order for my report to get the proper information. I have no idea how to do this :)

I received the error message
"Unable to connect: incorrect log on parameters."

Probably cuz i never stated any connection parameters :)

If anybody can help me out that would be fantastic.
 
hi
are u running asp pages with vb script behind?

pgtek
 
Hi here the code i use
<%@ Language=VBScript %>

<% Response.Buffer=True %>

<%

reportname= &quot;Name of your report.rpt&quot;

if Not IsObject (session(&quot;oApp&quot;)) then

Set session(&quot;oApp&quot;)= Server.CreateObject(&quot;CrystalRuntime.Application&quot;)

End If

Path = Request.ServerVariables(&quot;PATH_TRANSLATED&quot;)

While (Right(Path, 1) <> &quot;\&quot; And Len(Path) <> 0)

iLen = Len(Path) - 1

Path = Left(Path, iLen)

Wend

If IsObject(session(&quot;oRpt&quot;)) Then

set session(&quot;oRpt&quot;) = nothing

End If



Set session(&quot;oRpt&quot;) = session(&quot;oApp&quot;).OpenReport(path & reportname, 1)

'session(&quot;oRpt&quot;).DiscardSavedData



session(&quot;oRpt&quot;).MorePrintEngineErrorMessages = False

session(&quot;oRpt&quot;).EnableParameterPrompting = False



userid= &quot;your id&quot;
password= &quot;your password&quot;
dns=&quot;your DNS&quot;
db=&quot;your database&quot;
'set create table for as many table use in your report
'if you have 2 tables you have to cut and paste the
'and change the item() to 2 item(2)
--------------------------------------
set crtable = session(&quot;oRpt&quot;).Database.Tables.Item(1)

crtable.SetLogonInfo cstr(dns), cstr(db), cstr(userid), cstr(password)

if not crtable.TestConnectivity then

response.write &quot;ReCrystallize Warning: Unable to connect to data source using the following information.<BR><BR>&quot;

response.write &quot;Server / ODBC data source: &quot;& dns&&quot;<BR>&quot;

response.write &quot;Database / Table:&quot;& db &&quot; <BR>&quot;

response.write &quot;User Name: &quot; & userid & &quot;<BR>&quot;

response.write &quot;Password: &quot; & password & &quot;<BR><BR><BR>&quot;

end if
--------------------

cheers
pgtek
 
Im running aspx web form with vb code behind. Its all taking place on the server so there is no script sent to the client.

This is what i found and have so far to connect...
----------------
Private Sub PrintPreview(ByVal UserId As String, ByVal Password As String)

Dim myLogonInfo As CrystalDecisions.Shared.TableLogOnInfo

CrystalReportViewer1.LogOnInfo = New CrystalDecisions.Shared.TableLogOnInfos()

Dim tables() As String = &quot;tableName1&quot;, &quot;tableName2&quot;, &quot;tableName3&quot;, &quot;tableName4&quot; }

Dim i As Integer
For i = 0 To tables.Length - 1
'Create a new myLogonInfo table and set its properties
myLogonInfo = New CrystalDecisions.Shared.TableLogOnInfo()
myLogonInfo.TableName = tables(i)
With myLogonInfo.ConnectionInfo
.UserID = UserId
.Password = Password
End With
CrystalReportViewer1.LogOnInfo.Add(myLogonInfo)
Next

'Show the report
Dim myReport As New crtReport()
CrystalReportViewer1.ReportSource = myReport
CrystalReportViewer1.RefreshReport()
End Sub
--------------

This is still not working for me. It get the error &quot;Unable to connect: incorrect log on parameters&quot;

I created my report using Crystal Reports 9, and selected OLE DB to make my connectio to my sql server, but selected 'integrated security' and i am not sure if this option is what is causing trouble.

I also have stored procedures in my crystal report... i am 'guessing' that they should be added to the table array but to my understanding, it only applies for tables.


Thanks any advice
 
hi
i see in your code for the userid and password you have a dot in the beginning.
is this meaded or just mis type info

cheers

pgtek
 
hi..SidTheSquid
will u please let me know ..how to pass parameter to crystal report?.I think u can help me out!
I have posted my problem in detail on 26th june under title &quot;Unable to connect: incorrect log on parameters.&quot;
Please help me out
 
I answered ur post. I'll post my code first thing in the morning.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top