Saturday, February 23, 2008

Whitening Teeth White Spots

CONECTAR A DISTINTAS BASES DE DATOS DE SQL SERVER CON CRYSTAL REPORTS

need to understand the post: have knowledge of SQL Server, Crystal Reports and Visual Basic 6, and be familiar with the connections via ODBC.

seems that, since version 8 or 9, Crystal Reports, there is a problem when changing the database to which we connect when we launched a report, either by using modules or DRC. NET Crystal Reports. I remember having given it much thought at the time, when I had to set an administrator reporting filters and connection information via ODBC (DSN name, driver, host, username and password) so that it was easily configurable . By then loaded (unnecessarily) the data in a RecordSet with SQL Case report and was then assigned CRAXDRT.Report object in question. He believed that the method worked well, until I had to make a small pitcher of reports in Crystal Reports XI runtime and find that always attacked the database that is declared in the report source. After many headaches, and do many silly things, I found the solution to check the SQL of the report (which was the first thing I have done, milk).

seems that from version 8 onwards, came up with the brilliant idea of \u200b\u200bletting you save the information database to which the report was to connect explicitly in the FROM clause of the blessed sentence SQL. So, whatever you do with the connection string of the report, it is enough to find the SQL server that was linked to discard the new information or, if not found, likely to fail without more.

Fortunately, this problem has a solution without touching the SQL statement. Just edit the connection data in tables in the report (either by altering the ConnectionString or ConnectionProperties ) and alter the data source by Location property of the table. Then I leave the source code of a function that can tackle the problem:

Environment used: Visual Basic 6 SP6 runtime with Crystal Reports XI Release 2.
Database: SQL Server 2000. You may also be useful to Oracle.


AplicaCambios Public Function (ByRef crrep _ As CRAXDRT.Report
, strDsn As String, strServer As String, strDb _ As String
, Struan As String , strPwd As String, strDriver As String) As Boolean
Dim i As Integer
esSqlServer Dim As Boolean

AplicaCambios = True

'compared without distinguishing case. _
If this is a report from SQL Server will _
to process the Location of each table.

If InStr (1, strDriver, "SQL SERVER" vbTextCompare) Then
        esSqlServer = True
    Else
        esSqlServer = False
    End If

    For i = 1 To crrep.database.Tables.Count
        With Me . CrReport.database.Tables (i)
Call . ConnectionProperties.DeleteAll

Call . ConnectionProperties.Add ("DSN" strDsn)
; Call .ConnectionProperties.Add("Server", strServer)
            Call .ConnectionProperties.Add("Database", strDb)
            Call .ConnectionProperties.Add("User ID", strUid)
            Call .ConnectionProperties.Add("Password", strPwd)
            Call .ConnectionProperties.Add("UseDSNProperties", False )

            If esSqlServer Then
                On Error Resume Next
                .Location = strDb & ".dbo." & .Location

                If Err.Number Then
                    Call MsgBox ("Error while processing table names:" _
& vbCrLf &. Location & "in passing" _
& strDb & ".dbo." & .Location _
                    & vbCrLf & Err.Number & ": " & Err.Description)

                    AplicaCambios = False
                    Exit For
                End If
                On Error GoTo 0 End If

;
End With Next End Function
'AplicaCambios


Checking the driver does not know if you find it useful, in my case, The program I use to attack by ODBC SQL Server or plain text files, hence did not apply the change of the Location property forever.

Finally, I should mention that one advantage of Crystal Reports XI is not to be processing the subreports since all the tables are located in member CRAXDRT.Report Object Database. I remember that for version 9, it was necessary to go through all the sections to apply the changes.

I hope this helps someone. For suggestions or questions, are available to the comments.

0 comments:

Post a Comment