Database logon failed. crystal report 2008 in asp.net 3.5

HI,
I have created report in Crystal report 2008 on one PC which is working fine. When I change My PC i.e Copy rpt to another PC with different DB name but same schema, i not able to connect to that DB. Report shows msg as "Database logon failed."
For making work it proper I have written the following code to bind report.
Here I am passing Parameter as encrypted query string.
Query string contains RPT name, Parameter with values of Reports and FORMULAFIELD.
Kindly help me as soon as possible.
Thanks in advance for helping.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'ScriptManager.GetCurrent(Me).RegisterPostBackControl(crViewer)
        If Not Request.QueryString("ID") Is Nothing Then
            Dim strEncryptedParameters, strDecryptedParameters As String
            strEncryptedParameters = Request.QueryString("ID").ToString()
            Dim objEncryptDecrypt As EncryptDecrypt = New EncryptDecrypt()
            strDecryptedParameters = objEncryptDecrypt.DecryptString(strEncryptedParameters.ToString().Replace(" ", "+"))
            If strDecryptedParameters <> "" And Not strDecryptedParameters.Contains("Invalid character") Then
                Dim strParams() As String
                Dim strParameter() As String
                Dim strParameterName, strParameterValue As String
                Try
                    BindReport(strDecryptedParameters)
                    strParams = strDecryptedParameters.Split("##")

                    For Each strParameterNameValuePair As String In strParams
                        If strParameterNameValuePair <> "" Then
                            strParameter = strParameterNameValuePair.Split("=")
                            If strParameter.Length = 2 Then
                                strParameterName = strParameter(0)
                                strParameterValue = strParameter(1)
                            End If

                        End If
                    Next
                Catch ex As Exception
                    Response.Write("<script type='text/javascript'>window.close();</script>")
                End Try
                
            Else

            End If


        End If

    End Sub

    Private Sub BindReport(ByVal strDecryptedParameters As String)
        Try
            'Declaring variables
            Dim intCounter As Integer
            'Crystal Report's report document object
            Dim objReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument
            'object of table Log on info of Crystal report
            Dim ConInfo As New CrystalDecisions.Shared.TableLogOnInfo
            'Parameter value object of crystal report
            ' parameters used for adding the value to parameter.
            Dim paraValue As New CrystalDecisions.Shared.ParameterDiscreteValue
            'Current parameter value object(collection) of crystal report parameters.
            Dim currValue As CrystalDecisions.Shared.ParameterValues
            Dim strNameValPair() As String
            Dim strTempNameValPair() As String
            Dim strProcAttrNameValPair() As String
            Dim strVal() As String
            Dim index As Integer
            Try
                '   
                strNameValPair = strDecryptedParameters.Split("$$")
                For i = 0 To strNameValPair.Length - 1
                    strTempNameValPair = strNameValPair(i).Split("##")
                    Select Case strTempNameValPair(0)
                        Case "FORMULAFIELD"
                            For Each strTemp As String In strTempNameValPair
                                If strTemp <> "" And InStr(strTemp, "=") > 0 Then
                                    Dim strParamterNameValue() As String = strTemp.Split("=")
                                    objReport.DataDefinition.FormulaFields(strParamterNameValue(0)).Text = "'" & strParamterNameValue(1) & "'"
                                End If
                            Next

                        Case "REPORT"
                            Dim arrReportinfo As String = strTempNameValPair(1)
                            Dim arrTempReportinfo() As String
                            For Each strTemp As String In strTempNameValPair
                                If strTemp <> "" And InStr(strTemp, "=") > 0 Then
                                    arrTempReportinfo = strTemp.Split("=")
                                    '    'Load the report
                                    objReport.Load(HttpContext.Current.Server.MapPath("../RPT/" & arrTempReportinfo(1) & ".rpt"))
                                End If
                            Next

                        Case "PARAMETERS"
                            strProcAttrNameValPair = strTempNameValPair(1).Split("##")
                            'Check if there are parameters or not in report.
                            intCounter = objReport.DataDefinition.ParameterFields.Count
                            'Assign all the Paramters here in a Loop
                            If intCounter > 0 And Trim(strDecryptedParameters) <> "" Then
                                For index = 1 To UBound(strTempNameValPair)
                                    If InStr(strTempNameValPair(index), "=") > 0 Then
                                        strVal = strTempNameValPair(index).Split("=")
                                        paraValue.Value = strVal(1)
                                        currValue = objReport.DataDefinition.ParameterFields("@" & strVal(0)).CurrentValues
                                        currValue.Add(paraValue)
                                        objReport.DataDefinition.ParameterFields("@" & strVal(0)).ApplyCurrentValues(currValue)
                                    End If
                                Next
                            End If
                    End Select

                Next



                Dim dbInfo As New DatabaseInfo
                dbInfo = GetDatabaseInfo()
                'Set the connection information to ConInfo
                'object so that we can apply the
                'connection information on each table in the report
                ConInfo.ConnectionInfo.UserID = dbInfo.DbUserID
                ConInfo.ConnectionInfo.Password = dbInfo.DbPassword
                ConInfo.ConnectionInfo.ServerName = dbInfo.DatabaseServer
                ConInfo.ConnectionInfo.DatabaseName = dbInfo.DatabaseName
                For intCounter = 0 To objReport.Database.Tables.Count - 1
                    objReport.Database.Tables(intCounter).ApplyLogOnInfo(ConInfo)
                Next

                Dim logonInfo As New TableLogOnInfos()
                crViewer.LogOnInfo = GetLogonInfos(logonInfo)
                'Re setting control
                crViewer.ReportSource = Nothing
                'Set the current report object to report.
                crViewer.ReportSource = objReport
                'Show the report

            Catch ex As Exception
                Dim str As String = ex.Message
            End Try
        Catch ex As Exception
            Dim str As String = ex.Message
        Finally

        End Try
    End Sub

    Public Function GetDatabaseInfo() As DatabaseInfo
        Dim Dbinfo As New DatabaseInfo
        Dim strConnectionString As String = ""
        Dim arrInfo(), arrTempInfo() As String
        Dim strKey, strValue As String
        strConnectionString = ConfigurationManager.ConnectionStrings("Roshan").ToString
        arrInfo = strConnectionString.Split(";")
        For Each sectionEntry As String In arrInfo
            arrTempInfo = sectionEntry.Split("=")
            strKey = arrTempInfo(0).Replace(" ", "")
            strValue = arrTempInfo(1)
            Select Case strKey
                Case "InitialCatalog"
                    Dbinfo.DatabaseName = strValue
                Case "DataSource"
                    Dbinfo.DatabaseServer = strValue
                Case "UserID"
                    Dbinfo.DbUserID = strValue
                Case "Password"
                    Dbinfo.DbPassword = strValue
                Case "IntegratedSecurity"
                    Dbinfo.DbIntegratedSecurity = Convert.ToBoolean(strValue)
                Case "providerName"
                    Dbinfo.DbProviderName = strValue
            End Select
        Next
        GetDatabaseInfo = Dbinfo
        Return GetDatabaseInfo
    End Function

    Private Function GetLogonInfos(ByVal logonInfos As TableLogOnInfos) As TableLogOnInfos
        Dim dbInfo As New DatabaseInfo
        dbInfo = GetDatabaseInfo()
        ''This will add conn. info. to TableLogOnInfos collection
        Dim logonInfo As New TableLogOnInfo()
        logonInfo.ConnectionInfo.ServerName = dbInfo.DatabaseServer
        logonInfo.ConnectionInfo.DatabaseName = dbInfo.DatabaseName
        logonInfo.ConnectionInfo.UserID = dbInfo.DbUserID
        logonInfo.ConnectionInfo.Password = dbInfo.DbPassword
        logonInfo.ConnectionInfo.IntegratedSecurity = dbInfo.DbIntegratedSecurity
        logonInfos.Add(logonInfo)
        GetLogonInfos = logonInfos
    End Function

Open in new window

LVL 2
Fahad PathanTeam LeaderAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
mlmccConnect With a Mentor Commented:
If you use the SET LOCATION ability in Crystal does it require a differnet driver for SQL 2008?

mlmcc
0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
This will sound silly, but do you have permissions on that PC's database and schema?
0
 
Fahad PathanTeam LeaderAuthor Commented:
i am using admin rights for the same.
Also one more thing... when i created my rpt on first pc, its backend was MS SQL 2005 and when I trying to run it on another pc its backend is MS SQL 2008.
But when I save rpt on another PC then reports runs fine.
I cant do this for every rpt!!!
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
mlmccCommented:
Do you have to change the database driver when you change databases?  If so I don't think there is a way to do that through code.

mlmcc
0
 
Fahad PathanTeam LeaderAuthor Commented:
mlmcc:
Thanks for reply..
But i didnt got what you are trying to say....
0
 
Fahad PathanTeam LeaderAuthor Commented:
ok.. so on another PC I have SQL 2008 and on my web hosting server having same version, and if I save that report on another PC again will it work in my web hosting server?
0
 
Fahad PathanTeam LeaderAuthor Commented:
whenever you create CR on any version of MS SQL Server, if change the version of MS SQL Server, do set the location of report again.
0
All Courses

From novice to tech pro — start learning today.