Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have a Crystal report with 50 odd subreports, each with loads of parameters. Switching it from one database to another takes ages as the Crystal Reports IDE insists that you enter all the parameters for each sub-report.
I'm wondering if it's possible to write a quick tool in C# to view the current database config of all of the sub-reports in an rpt file, and ideally to switch to a different database.
Unfortunately (or fortunately) I don't have much experience of the Crystal object model - anyone know where to start?
Thanks,
Jon.
This should do the job. Obviously replace the passwords and User names where neccesary.
Private Sub ProcessFile(ByVal FileName As String)
Dim CR As Engine.ReportDocument = Nothing
Try
CR = New Engine.ReportDocument
CR.Load(FileName, CrystalDecisions.Shared.OpenReportMethod.OpenReportByDefault)
'Recurse thru Report
RecurseAndRemap(CR)
'Save File
CR.SaveAs("OutPutFilePath")
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
If Not CR Is Nothing Then
CR.Close()
CR.Dispose()
End If
End Try
End Sub
Private Sub RecurseAndRemap(ByVal CR As Engine.ReportDocument)
For Each DSC As CrystalDecisions.Shared.IConnectionInfo In CR.DataSourceConnections
DSC.SetLogon("YourUserName", "YourPassword")
DSC.SetConnection("YouServerName", "YourDatabaseName", False)
Next
CR.SetDatabaseLogon("YourUserName", "YourPassword")
For Each Table As Engine.Table In CR.Database.Tables
Table.LogOnInfo.ConnectionInfo.UserID = "YourUserName"
Table.LogOnInfo.ConnectionInfo.Password = "YourPassword"
Next
If Not CR.IsSubreport Then
For Each SR As Engine.ReportDocument In CR.Subreports
RecurseAndRemap(SR)
Next
End If
End Sub
Hope that helps Cheers Ben
In VB6 we use something like next (dirty copy-paste form old code, incrementally updated from CR6 to CR9), maybe you can get some ideas:
For Each tmpTable In Report.Database.Tables
Set CPProperties = tmpTable.ConnectionProperties
CPProperties.DeleteAll
CPProperties.Add "Provider", "SQLOLEDB"
CPProperties.Add "Data Source", mServerName
CPProperties.Add "Initial Catalog", mBaseName
CPProperties.Add "User ID", mUserID
CPProperties.Add "Password", mPassword
CPProperties.Add "Server Name", mServerName
CPProperties.Add "Server Type", "OLEDB"
CPProperties.Add "DataBase", mBaseName
tmpTable.SetTableLocation tmpTable.Location, "", ""
Next tmpTable
For Each tmpSection In Report.Sections
For Each tmpObject In tmpSection.ReportObjects
If TypeName(tmpObject) = "ISubreportObject" Then
Set tmpReport = tmpObject.OpenSubreport()
For Each tmpTable In tmpReport.Database.Tables
Set CPProperties = tmpTable.ConnectionProperties
CPProperties.DeleteAll
CPProperties.Add "Provider", "SQLOLEDB"
CPProperties.Add "Data Source", mServerName
CPProperties.Add "Initial Catalog", mBaseName
CPProperties.Add "User ID", mUserID
CPProperties.Add "Password", mPassword
CPProperties.Add "Server Name", mServerName
CPProperties.Add "Server Type", "OLEDB"
CPProperties.Add "DataBase", mBaseName
tmpTable.SetTableLocation tmpTable.Location, "", ""
Next tmpTable
End If
Next tmpObject
Next tmpSection
Bit of experimentation seems to solved the problem:
private void Form1_Load(object sender, EventArgs e)
{
ReportDocument rd = new ReportDocument();
rd.Load("Report.rpt");
Explore(rd);
foreach (ReportDocument sr in rd.Subreports)
{
Explore(sr);
}
}
private void Explore(ReportDocument r)
{
foreach (IConnectionInfo con in r.DataSourceConnections)
{
if (!r.IsSubreport)
Console.WriteLine("Main Report");
else
Console.WriteLine(r.Name);
Console.WriteLine(con.DatabaseName);
Console.WriteLine("-");
}
}
Related
I wanted to get bugs and test defect's Related Work Items and AssignedTo of these Related Work Items.
In the code below, I can get AssignedTo of Bug/Test Defect, however, I can't get AssignedTo of Related Work Item.
How can I add this information to OData Query?
Thanks
let
Source = OData.Feed ("https://analytics.dev.azure.com/{Organization}/{ProjectName}/_odata/v3.0-preview/WorkItems?"
&"$filter=WorkItemType in ('Bug','Test Defect') "
&"and startswith(Area/AreaPath,'RoofTickets') "
&"&$select=WorkItemId,Title,WorkItemType,State,AssignedTo "
&"&$expand=AssignedTo($select=UserName),Iteration($select=IterationPath),Area($select=AreaPath), "
&"Links( "
&"$filter=LinkTypeName eq 'Related' "
&"and TargetWorkItem/WorkItemType eq 'User Story'; "
&"$select=LinkTypeName; "
&"$expand=TargetWorkItem($select=WorkItemType,WorkItemId,Title,State) "
&") "
,null, [Implementation="2.0"]),
#"Expanded AssignedTo" = Table.ExpandRecordColumn(Source, "AssignedTo", {"UserName"}, {"UserName"}),
#"Expanded Links" = Table.ExpandTableColumn(#"Expanded AssignedTo", "Links", {"LinkTypeName", "TargetWorkItem"}, {"LinkTypeName", "TargetWorkItem"}),
#"Filtered Rows" = Table.SelectRows(#"Expanded Links", each ([LinkTypeName] = "Related"))
in
#"Filtered Rows"
I have this script below to add roles and members and permissions
Import-Module sqlserver
$Server = new-Object Microsoft.AnalysisServices.Tabular.Server
$Server.Connect("SERVER\INSTANCE")
$TabDB = $SERVER.Databases["DATABASENAME"]
$AddRole = new-Object Microsoft.AnalysisServices.Tabular.ModelRole
$AddRole.Name = 'NewRole1'
$AddRole.ModelPermission="Read"
$RoleMember = New-Object Microsoft.AnalysisServices.Tabular.WindowsModelRoleMember
$RoleMember.MemberName = 'DOMAIN\ACCOUNT'
$TabDB.Model.Roles.Add($AddRole)
$AddRole.Members.Add($RoleMember)
$TabDB.Update([Microsoft.AnalysisServices.UpdateOptions]::ExpandFull)
$server.Disconnect()
How can I remove a permission, a member, and a role?
I tried this at least for the role, but the console returns back "False"
$TabDB.Model.Roles.Remove($AddRole)
When working with ssas from powershell (or C# for that matter) you can use the analysisservices namespace of microsoft:
Microsoft analysisservices.
This is an object oriented way of working with ssas databases.
This is an old script I wrote for maintainers:
function addRoleToDb {
$roleName = Read-Host "How should this role be called?"
if ($global:dataBase.Roles.findByName($roleName)) {
echo "This role already exists"
return
} elseif ($roleName -eq "") {
echo "You can't give an empty name for a role."
return
}
echo "Warning: this role will start out empty and will have to be modified in order to be used. (it wil have read permission)"
[Microsoft.AnalysisServices.Role] $newRole = New-Object([Microsoft.AnalysisServices.Role])($roleName)
$global:dataBase.Roles.add($newRole)
$dbperm = $global:dataBase.DatabasePermissions.add($newRole.ID)
$dbperm.Read = [Microsoft.AnalysisServices.ReadAccess]::Allowed
$global:dataBase.Roles.Update()
$dbperm.Update()
return
}
At this point I already had a global variable database.
This is a method that would add a role to the database. Deleting the database would work practically the same, you would get the instance of the role with:
role = database.roles.findbyname()
or
role = database.roles.findbyid()
and then
role.Drop(DropOptions.AlterOrDeleteDependents);
You should check that last line before using it because the alterordeletedependants is something I now use in my c# program, I don't remember if it worked in powershell.
Good luck!
The following is in a file all on its own:
<%
Dim mailtest
Set mailtest = CreateObject("CDO.Message")
mailtest.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
mailtest.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")="localhost"
mailtest.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
mailtest.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")=0
mailtest.Configuration.Fields.Update
mailtest.Subject = "Test email"
mailtest.From = "test#test.com"
mailtest.To = "test#test.com"
mailtest.HTMLBody = "£££"
mailtest.Send
%>
I'm using smtp4dev to receive the emails. When I open the email, the body is simply "###".
What on earth could be causing this? I could understand if they were changing to question marks or something due to encoding issues, but why might they be changing to hashes?
I have more than 100 reports in SSRS report server. I need to enable caching for all of those. Right now I am enabling caching through the report manager for each and every report.
Can we add caching in any of the report servers config files? So that we can enable caching for all reports at a single place.
Any help will be appreciated
Thanks
AJ
Below is the script that I used to enable caching in minutes on a list of reports.
Save it as setreportscaching.rss and then run it from the command line:
rs.exe -i setreportscaching.rss -e Mgmt2010 -t -s http://mySsrsBox:8080/ReportServer -v ReportNamesList="OneReport,AnotherReport,YetAnotherOne" -v CacheTimeMinutes="333" -v TargetFolder="ReportsFolderOnServer"
It is easy to modify it to loop through files in some folder rather then take csv list of reports. It has some silly piece of diagnostics that can be commented out for speed.
Public Sub Main()
Dim reportNames As String() = Nothing
Dim reportName As String
Dim texp As TimeExpiration
Dim reportPath As String
Console.WriteLine("Looping through reports: {0}", ReportNamesList)
reportNames = ReportNamesList.Split(","c)
For Each reportName In reportNames
texp = New TimeExpiration()
texp.Minutes = CacheTimeMinutes
reportPath = "/" + TargetFolder + "/" + reportName
'feel free to comment out this diagnostics to speed things up
Console.WriteLine("Current caching for " + reportName + DisplayReportCachingSettings(reportPath))
'this call sets desired caching option
rs.SetCacheOptions(reportPath, true, texp)
'feel free to comment out this diagnostics to speed things up
Console.WriteLine("New caching for " + reportName + DisplayReportCachingSettings(reportPath))
Next
End Sub
Private Function DisplayReportCachingSettings(reportPath as string)
Dim isCacheSet As Boolean
Dim expItem As ExpirationDefinition = New ExpirationDefinition()
Dim theResult As String
isCacheSet = rs.GetCacheOptions(reportPath, expItem)
If isCacheSet = false Or expItem is Nothing Then
theResult = " is not defined."
Else
If expItem.GetType.Name = "TimeExpiration" Then
theResult = " is " + (CType(expItem, TimeExpiration)).Minutes.ToString() + " minutes."
ElseIf expItem.GetType.Name = "ScheduleExpiration" Then
theResult = " is a schedule"
Else
theResult = " is " + expItem.GetType.Name
End If
End If
DisplayReportCachingSettings = theResult
End Function
I Have a vb6 application using crystal report 8.5 and sql server 2005.My issue is that when I print report i get Server has not yet been opened.Here is my code in vb.:
Option Explicit
Dim ctr As Integer
Dim cn As New ADODB.Connection--Provider=SQLOLEDB.1;Password=password;Persist Security Info=True;User ID=user ID;Initial Catalog=database Name;Data Source=server Name
Dim crApp As CRAXDRT.Application
Dim crReport As CRAXDRT.Report
Dim crtable As CRAXDRT.DatabaseTable
Private Sub prin_Click()
Dim rs As New ADODB.Recordset
Set cn = New ADODB.Connection
cn.ConnectionString = MDI1.txtado
cn.Open
Set rs = New ADODB.Recordset
rs.Open "select * from temp_abs_yes", cn, adOpenKeyset, adLockOptimistic
Set crApp = New CRAXDRT.Application
Set crReport = crApp.OpenReport("C:\Users\user1.dom\Desktop\ANP\abs_yes.rpt")
crReport.Database.Tables.Item(1).SetLogOnInfo "servername", "databasename", "user", "password"
crReport.Database.Tables.Item(1).SetDataSource rs, 3
crReport.DiscardSavedData
Viewer.ReportSource = crReport
Viewer.ViewReport
rs.close
Set rs = Nothing
Set crReport = Nothing
Set crApp = Nothing
End Sub
I think doing "SetLogOnInfo" is innecesary in that case, as you are assigning the data to report
Probably is not your case, but for the help of someone else.
I got that error when I assigned the servername parameter incorrectly.
The correct parameters I used for logon (for an oracle DB):
[...]Item(1).SetLogOnInfo "[tnsnames]", "", "[db user]", "[db password]"
I resolved by updating dll
p2soledb.dll
in c:\Windows\Crystal I got the details from here