C# ChangeDBLogoninaCrystalReportandSubreports Snippets

C# ChangeDBLogoninaCrystalReportandSubreports Snippets

11. June 2009

Read this article in your language IT | EN | DE | ES

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>Change the Server name and Database name</Title>
            <Author>Business Objects</Author>
            <Description>Changes a Server name and Database name used by the report.  For this code snippet to compile, add a reference to CrystalDecisions.CrystalReports.Engine.dll and CrystalDecisions.Shared.dll.</Description>
            <HelpUrl>http://www.businessobjects.com/products/dev_zone/net/default.asp</HelpUrl>
            <Shortcut>crChangeDBLogon</Shortcut>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
                <Literal>
                    <ID>FileName</ID>
                    <Type>String</Type>
                    <ToolTip>Replace this string with the name of the report file that you want to change the database logon.</ToolTip>
                    <Default>"C:\My Crystal Reports\Report Name.rpt"</Default>
                </Literal>
                <Literal>
                    <ID>OldServerName</ID>
                    <Type>String</Type>
                    <ToolTip>Replace this string with the old server name that is used in the report. </ToolTip>
                    <Default>"OldServer"</Default>
                </Literal>
                <Literal>
                    <ID>NewServerName</ID>
                    <Type>String</Type>
                    <ToolTip>Replace this string with the new server name that the report will be using. </ToolTip>
                    <Default>"NewServer"</Default>
                </Literal>
                <Literal>
                    <ID>OldDatabaseName</ID>
                    <Type>String</Type>
                    <ToolTip>Replace this string with the old database name that is used in the report. </ToolTip>
                    <Default>"OldDatabase"</Default>
                </Literal>
                <Literal>
                    <ID>NewDatabaseName</ID>
                    <Type>String</Type>
                    <ToolTip>Replace this string with the new database name that the report will be using. </ToolTip>
                    <Default>"NewDatabase"</Default>
                </Literal>
                <Literal>
                    <ID>UserID</ID>
                    <Type>String</Type>
                    <ToolTip>Replace this string with the user ID to logon to the new server. </ToolTip>
                    <Default>"MyUserID"</Default>
                </Literal>
                <Literal>
                    <ID>Password</ID>
                    <Type>String</Type>
                    <ToolTip>Replace this string with the user's password to logon to the new server. </ToolTip>
                    <Default>"MyPassword"</Default>
                </Literal>
        <Literal Editable="false">
          <ID>ReportDocumentClass</ID>
          <Function>SimpleTypeName(CrystalDecisions.CrystalReports.Engine.ReportDocument)</Function>
        </Literal>
        <Literal Editable="false">
          <ID>IConnectionInfoClass</ID>
          <Function>SimpleTypeName(CrystalDecisions.Shared.IConnectionInfo)</Function>
        </Literal>        
            </Declarations>
            <Code Language="csharp">
        <![CDATA[$ReportDocumentClass$ report = new $ReportDocumentClass$();          
          string oldServerName = $OldServerName$;
          string newServerName = $NewServerName$;
          string oldDatabaseName = $OldDatabaseName$;
          string newDatabaseName = $NewDatabaseName$;
          string userID = $UserID$;
          string password = $Password$;
          
          report.Load(@$FileName$);
          
          // Change the server name and database in main reports          
          foreach($IConnectionInfoClass$ connection in report.DataSourceConnections)
          {
            if ((String.Compare(connection.ServerName, oldServerName, true) == 0) &&
              (String.Compare(connection.DatabaseName, oldDatabaseName, true) == 0))
            {
              // SetConnection can also be used to set new logon and new database table
              report.DataSourceConnections[oldServerName, oldDatabaseName].SetConnection(
                newServerName, newDatabaseName, userID, password);
            }
          }     
          
          // Change the server name and database in subreport
          foreach($ReportDocumentClass$ subReport in report.Subreports)
          {
            foreach($IConnectionInfoClass$ connection in subReport.DataSourceConnections)
            {
              if ((String.Compare(connection.ServerName, oldServerName, true) == 0) &&
                (String.Compare(connection.DatabaseName, oldDatabaseName, true) == 0))
              {
                // SetConnection can also be used to set new logon and new database table
                subReport.DataSourceConnections[oldServerName, oldDatabaseName].SetConnection(
                  newServerName, newDatabaseName, userID, password);
              }
            }
          }$end$]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>
FacebookDigg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

C#

Comments

8/14/2009 9:06:38 PM #
I like how you write.Are you interesting in a part time writer job?
8/16/2009 7:26:02 PM #
Please let me know if you are interested to work as article writer for me? I can offer $10/article.
8/27/2009 6:04:14 AM #
I think you have to improve a bit the design and usability of your blog.
5/7/2010 5:36:31 AM #
What a brilliant web page!
5/9/2010 9:33:23 AM #
Appreciation 4 taking the time to debate c#, I feel strongly all about it and love learning more on this issue. If likely, since you gain expertise, would you�d mind updating your weblog with more information? Extremely beneficial for me.
5/9/2010 9:33:33 AM #
c# c# c# I completely trust the above remark, the internet is having a doubt growing into crucial medium of communication across the world & its as a result of web-sites like this that ideas are spreading so quickly
5/17/2010 12:43:10 AM #
I feel strongly all about it and love learning more on this issue. If likely, since you gain expertise, would you�d mind updating your weblog with more information? Extremely beneficial for me.
5/21/2010 5:09:25 PM #
You made numerous nice ideas there. I done a search on the issue and learnt nearly all peoples will agree with your blog.
5/22/2010 1:30:33 AM #
well, anybody who has been seriously engaged is scientific work of any kind realizes that over the entrance to the gates of the temple of science are written the words: 'Ye must have faith.' Carla

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Sayfa 0.03125 saniyede yuklendi.