Skip to Content
0
Former Member
Nov 24, 2009 at 08:13 AM

Problem with changing database runtime...

20 Views

Hi:)

<br><br>

We are developing a ASP.NET solution where we are using crystal report .net.

But we have ran into one problem, namely changing the reports database at runtime. Our code for that is below.<br>

It works locally, but when running it on the production server we got the error "database login error".<br>

If we call it with databasename, server, integratedSecurity = true on the production server, then it will ONLY WORK <br>

if we also provide a username and password. <br>

What is the meaning with that? I can't understand why we should provide username and password when <br>

integrated Security is set to true? Is this a bug or.... With integrated security it should take the logged in username and password from windows.

<br><br>

Sincerly Jan, Denmark<br>

<br><br>

Private Function AendreRapportDB_NY(ByVal Report As Object, ByVal Dbnavn As String, ByVal userid As String, ByVal passw As String, ByVal Server As String, ByVal integratedSecurity As Boolean, ByVal DSN As String) As Boolean<br>

Dim oCRDb As CrystalDecisions.CrystalReports.Engine.Database = myReportDocument.Database<br>

Dim oCRTables As CrystalDecisions.CrystalReports.Engine.Tables = oCRDb.Tables<br>

Dim oCRTable As CrystalDecisions.CrystalReports.Engine.Table<br>

Dim oCRTableLogonInfo As CrystalDecisions.Shared.TableLogOnInfo<br>

Dim oCRConnectionInfo As New CrystalDecisions.Shared.ConnectionInfo()

oCRConnectionInfo.ServerName = Server<br>

oCRConnectionInfo.DatabaseName = Dbnavn<br>

oCRConnectionInfo.IntegratedSecurity = integratedSecurity<br>

oCRConnectionInfo.UserID = userid<br>

oCRConnectionInfo.Password = passw<br>

oCRConnectionInfo.Type = ConnectionInfoType.SQL<br>

For Each oCRTable In oCRTables<br>

Dim nvp As CrystalDecisions.Shared.NameValuePair2<br>

For Each nvp In oCRTable.LogOnInfo.ConnectionInfo.Attributes.Collection<br>

If String.Compare(nvp.Name, "QE_LogonProperties", True) = 0 Then<br>

Dim dca As DbConnectionAttributes = nvp.Value<br>

Dim nvp1 As NameValuePair2<br>

For Each nvp1 In dca.Collection<br>

Select Case UCase(nvp1.Name)<br>

Case "Database DLL"<br>

nvp1.Value = "crdb_odbc.dll"<br>

Case "DSN"<br>

nvp1.Value = DSN<br>

Case "DATABASE"<br>

nvp1.Value = Dbnavn<br>

Case "USEDSNPROPERTIES"<br>

nvp1.Value = "True"<br>

End Select<br>

'Current.Response.Write("2." & nvp1.Name & " = " & nvp1.Value & "<br>")

Next<br>

Else<br>

Select Case UCase(nvp.Name)<br>

Case "QE_DatabaseName"<br>

nvp.Value = Dbnavn<br>

Case "QE_DatabaseType"<br>

nvp.Value = "ODBC (RDO)"<br>

Case "QE_SQLDB"<br>

nvp.Value = True<br>

End Select<br>

'Current.Response.Write("1." & nvp.Name & " = " & nvp.Value & "<br>")

End If<br>

Next<br>

<br><br>

oCRTableLogonInfo = oCRTable.LogOnInfo<br>

oCRTableLogonInfo.ConnectionInfo = oCRConnectionInfo<br>

oCRTable.ApplyLogOnInfo(oCRTableLogonInfo)<br>

<br><br>

Dim crReportObjects As ReportObjects<br>

Dim crSection As Section<br>

For Each crSection In myReportDocument.ReportDefinition.Sections<br>

crReportObjects = crSection.ReportObjects<br>

'Next<br>

Dim crReportObject As ReportObject<br>

For Each crReportObject In crReportObjects<br>

If (crReportObject.Kind = CrystalDecisions.Shared.ReportObjectKind.SubreportObject) Then<br>

Dim crSubreportObject As SubreportObject = crReportObject<br>

Dim crSubreportDocument As ReportDocument<br>

crSubreportDocument = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName)<br>

Dim crDatabase As CrystalDecisions.CrystalReports.Engine.Database<br>

Dim crTables As CrystalDecisions.CrystalReports.Engine.Tables<br>

Dim aTable As CrystalDecisions.CrystalReports.Engine.Table<br>

crDatabase = crSubreportDocument.Database<br>

crTables = crDatabase.Tables<br>

For Each aTable In crTables<br>

oCRTableLogonInfo = aTable.LogOnInfo<br>

oCRTableLogonInfo.ConnectionInfo = oCRConnectionInfo<br>

aTable.ApplyLogOnInfo(oCRTableLogonInfo)<br>

Next<br>

'Response.Write(crSubreportObject.SubreportName)<br>

End If<br>

Next<br>

Next<br>

Next<br>

End Function<br>

Edited by: Jan Tovgaard on Nov 24, 2009 9:24 AM