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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crystal always asks for SQL logon info, how to stop this?

Status
Not open for further replies.

ajonesprogrammer

Programmer
Nov 8, 2005
3
US
Everytime I run a crystal report it asks for my sql logon information. I have already tried hardcoding connection info and applying the database name and userid and password. Below is the code for the call to the report:

'Bind to crystal
Try
Dim crConnInfo As New ConnectionInfo
Dim crReportDocument As New CrystalReport1
Dim CrTables As Tables
Dim CrTable As Table
Dim crtableLogoninfos As New TableLogOnInfos
Dim crtableLogoninfo As New TableLogOnInfo

myConnection_1 = New SqlConnection("Data Source=rotary_whse;user id=sa;password=truelies;" & _
"Initial Catalog=PaintLineTemp;")
MyCommand_1.Connection = myConnection
MyCommand_1.CommandText = "SELECT * FROM tblTemp"
MyCommand_1.CommandType = CommandType.Text
myDA.SelectCommand = MyCommand

myDA.Fill(myDS, "tblTemp")

With crConnInfo
.DatabaseName = "ROTARY_WHSE"
.UserID = "pline"
.Password = "410989"
End With

CrTables = crReportDocument.Database.Tables

'Loop through each table in the report and apply the
'LogonInfo information

For Each CrTable In CrTables
CrTableLogonInfo = CrTable.LogonInfo
crtableLogoninfo.ConnectionInfo = crConnInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)

'If your DatabaseName is changing at runtime, specify
'the table location.
'For example, when you are reporting off of a
'Northwind database on SQL server you
'should have the following line of code:

'CrTable.Location = "PaintLineTemp.dbo." & CrTable.Location.Substring(CrTable.Location.LastIndexOf(".") + 1)
Next

rpt.SetDataSource(myDS)
CrystalReportViewer1.ReportSource = rpt
myConnection.Close()
myConnection_1.Close()
Catch Excep As Exception
MessageBox.Show(Excep.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

As you can see, I have utilized code straight from Crystal Reports help website and it DOES NOT work. Any help would be great.

Thanks in advance.
 
Hi, where did you get this example?

to me this doesn't make sense because you first try to set
tables on your report

Code:
 For Each CrTable In CrTables
                CrTableLogonInfo = CrTable.LogonInfo
                crtableLogoninfo.ConnectionInfo = crConnInfo
                CrTable.ApplyLogOnInfo(crtableLogoninfo)

                'If your DatabaseName is changing at runtime, specify 
                'the table location. 
                'For example, when you are reporting off of a 
                'Northwind database on SQL server you 
                'should have the following line of code: 

                'CrTable.Location = "PaintLineTemp.dbo." & CrTable.Location.Substring(CrTable.Location.LastIndexOf(".") + 1)
            Next

and then you assign a recordset to the report and by doing this you overwrite the previous settings which by the way it has different user and pwd

Code:
  myConnection_1 = New SqlConnection("Data Source=rotary_whse;user id=sa;password=truelies;" & _
                                             "Initial Catalog=PaintLineTemp;")
            MyCommand_1.Connection = myConnection
            MyCommand_1.CommandText = "SELECT * FROM tblTemp"
            MyCommand_1.CommandType = CommandType.Text
            myDA.SelectCommand = MyCommand

            myDA.Fill(myDS, "tblTemp")

 rpt.SetDataSource(myDS)

Mo
 
Thank you for your response MisterMo. You'll have to forgive my ignorance in using Crystal being as this is the first time. I did get around this error though by just creating a user on SQL server that matched my domain user name and password. And then I switched the Crystal Report and Dataset that I use to utilize Integrated Security instead of a custom userID and Password.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top