Background:
I have an old report in which I am trying to add a table and a field. The report works perfectly fine in my web application. (Crystal reports ver. 11.5.9.1076)
After adding a table I get the error:
System.Runtime.InteropServices.COMException: Failed to open connection
This happens whether I add a table, command, or stored procedure to the report. (Connecting to Oracle database)
Things I've tried:
Add table (crashes), remove table (works again)
Click the "Verify database" button in the Database menu
Set database location and update the newly added table
Previewing the report seems to work
As for how I'm providing the data:
Create and load ReportDocument (VB.net)
Populate DataSet
Call SetDataSource method with DataSet as param
ExportToHttpResponse as PortableDocFormat
Here is what we had to do in order to make this work in our crystal reports: after loading the report, we loop through each of the DataSourceConnections in the report and update the connection information.
For Each oConnection As IConnectionInfo In oReport.DataSourceConnections
If fUseIntegratedSecurity Then
oConnection.SetConnection(sServerName, sDatabaseName, True)
Else
oConnection.IntegratedSecurity = False
oConnection.SetConnection(sServerName, sDatabaseName, sUserLogon, sUserPassword)
End If
Next
The actual connection details are provided elsewhere in our app, so I am just showing placeholders in the code above.
Related
I'm using a ConnectionString located at a Module for all of my Code in the project.
Code:
Public connString As String = "Data Source=192.168.1.11,1433;Network Library=DBMSSOCN;Initial Catalog=MY_DB;User Id=sa;Password = abc#1234
But for the Crystal Reports, I have added a project Data Source using project > add new Data Source > New Connection and used a ConnectionString.
After adding, I can see the Table and Fields. Once I add this to a Report, and browse Data through Field explorer, I don't see any Data. When I add the fields to a report, same happens. But, in the actual Table there are Rows.
What am I doing wrong here?
Using a DetailsView control on a web page coding in VB.Net Framework 4.5.2 on Visual Studio (Think its VS 2014). Need it to delete an item from a database (.mdf file format). The database is provided by the class, but the auto generation option for the Edit, Delete, and New keys is locked out for some reason.
I have the Edit, and New buttons working, as I could get that out of the book and it was easy to adjust them for this database. What I can't get to work is the line for delete. Here is what I have (Adjusted from the book I'm using):
DELETE FROM Schedule WHERE (ID = #ID)
When I go to debug it, I get the following error:
Must declare the scalar variable "#ID".
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Must declare the scalar variable "#ID".
I don't know where to go from here.
dim cmd as new sqlcommand("Delete from tablename where ID=#id",constring)
cmd.parameters.add("#id", idno.text)
cmd.executenonquery
This is how u should do it
I have an application developed in VB6 which I am migrating to .Net Framework 4.0. There is a report that works correctly in the original application but the migrated application does not work on the original application. As a special feature, this report changed at runtime attribute "location" in two tables (actually they are seen) used to generate the SQL with which the report is fed, but when "shooting" the reporete the changes in tables with the attribute "location" are not reflected, that I can display using the "SQL Server Profiler" tool:
objReportDocument.Database.Tables(0).Location = "NameReferenceTable""
My point is this: When the report was build, they used 5 database tables of the data base: Table1, Table2, Table3, Table4 and Table5. Later, in de data base, the tables Table1 and Table2 were deleted. The idea is that en run time a store procedure constructed Table1 and Table2 like temporary tables with the original name more any id string; this new data base tables must be used when the report are rise.
When you walk over the Tables array of the report (ReportDocument.DataBase.Tables(n)), for each table you can see two key properties: Name and Location. I understand than Location propertie indicates to Crystal Reports with which tables should work to build the reorts, this is true?
I have not much experience with Crystal Reports, I investigated two weeks why this error is generated without an answer ... I hope you can help me a bit, I really appreciate it.
regards,
Fabian.
I will provide a method that I use for our Crystal Reports objects in my application. This is just used to set the login information for the report (our reports use built-in security), but if I am understanding your problem correctly, then you should be able to add/modify this method to set the Location as well.
The properties used in the method below are:
Me.ConnectionInfo is type CrystalDecisions.Shared.ConnectionInfo
Me.LogOnInfo is type CrystalDecisions.Shared.TableLogOnInfo
Me.Report is type CrystalDecisions.CrystalReports.Engine.ReportDocument
Also, g_strDb, g_strServer, and g_strMirror are some Strings whose value is irrelevant.
One thing I have found working with Crystal Reports in .NET, is that you need to set properties at the Table level, as you can see in the method below. Hopefully this helps you with your issue.
''' <summary>
''' Apply the database connection info to all tables recursively.
''' </summary>
''' <param name="crxRpt">The report document (or subreport) to apply connection info.</param>
Private Sub SetConnectionInfo(ByVal crxRpt As ReportDocument)
Dim reportObject As ReportObject
Dim subReportObject As SubreportObject
Dim section As Section
Dim t As Table
For Each t In crxRpt.Database.Tables
' if the DatabaseName in the report is <special db name>,
' we need to make sure to set the DatabaseName to the environment
' that the user is currently connected to in order to be able to
' pull the correct information for the report
If t.LogOnInfo.ConnectionInfo.DatabaseName = "<special db name>" Then
Me.ConnectionInfo.DatabaseName = g_strDb
Else
Me.ConnectionInfo.DatabaseName = t.LogOnInfo.ConnectionInfo.DatabaseName
End If
' only ApplyLogOnInfo for tables that are being pulled from the SQL
' server, this avoids problems that arise with reports that are
' created using field definition files
If t.LogOnInfo.ConnectionInfo.ServerName = g_strServer OrElse t.LogOnInfo.ConnectionInfo.ServerName = g_strMirror Then
t.ApplyLogOnInfo(Me.LogOnInfo)
End If
Next t
For Each section In crxRpt.ReportDefinition.Sections
For Each reportObject In section.ReportObjects
If reportObject.Kind = ReportObjectKind.SubreportObject Then
subReportObject = CType(reportObject, CrystalDecisions.CrystalReports.Engine.SubreportObject)
SetConnectionInfo(subReportObject.OpenSubreport(subReportObject.SubreportName))
End If
Next reportObject
Next section
End Sub
The above method is called from a setup method:
''' <summary>
''' Initialize the database connection info.
''' </summary>
Public Sub SetUpReport()
Me.LogOnInfo = New TableLogOnInfo
Me.ConnectionInfo.UserID = conUID
Me.ConnectionInfo.Password = conPWD
Me.ConnectionInfo.ServerName = g_strServer
Me.ConnectionInfo.DatabaseName = g_strDb
Me.SetConnectionInfo(Me.Report)
End Sub
And SetUpReport() is called any time we need to display/print the report.
Well, finally find the solution...
In my conection to BD use ODBC, the associate user to this conection no had a schema associate in the BD, then when the store procedure created the temporaly tables there are creates below the shchema bdo, but when crystal reports rise the report (used my ODBC with the associate user) no found the temporaly tables. So I associated a scheemma to the user used in my ODBC.
My original reports are old, then I had to open each one in VS2012, overwrite the report to update the format and test in Main Report Preview.
When I ran my crystal report, I run into an error where its shows missing parameter values
Below is my code
_crAdviceRpt.Load("C:\Users\whatever\AD_AdviceTemplate.rpt")
Dim ds As ADDataset = New ADDataset
Dim dt As DataTable = ds.Tables.Add("ADDatatable")
dt.Columns.Add(New DataColumn("strLinesList", Type.GetType("System.String")))
Dim dr As DataRow
dr = dt.NewRow
dr("strLinesList") = strLine
dt.Rows.Add(dr)
_crAdviceRpt.SetDataSource(ds.Tables(1))
CrDiskFileDestinationOptions.DiskFileName = "location.pdf"
CrExportOptions = _crAdviceRpt.ExportOptions
With CrExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.PortableDocFormat
.DestinationOptions = CrDiskFileDestinationOptions
.FormatOptions = CrFormatTypeOptions
End With
_crAdviceRpt.Export()
If Not _crAdviceRpt Is Nothing Then
_crAdviceRpt.Close()
_crAdviceRpt.Dispose()
_crAdviceRpt = Nothing
End If
In my dataset, it does like this:
ADDDataset.xsd-> ADDatatable -> strLinesList
strLinesList is my column over here
In crystal report designer, I drag the strLinesList over to my .rpt
I'm not sure what is wrong but I'm pretty sure that something is missing in my code, so anyhere is appreciated
The Solution for this is to reorder the Crystal Parameters to match the Query Prompts
1) Open the problem report in Crystal Designer
2) Right click the Parameters section and select reorder parameters
3) Set the Parameter order to match that of the Prompts in the query
4) save the report and retest
The Verify Database command on the Database menu checks the alias pointers stored in a report file to verify that the database files expected are located in the indicated directories. If the databases are not found in the specified location, the program notifies you of the discrepancies.
Using the Verify Database process
When you choose Verify Database from the Database menu, the program checks the active databases and reports. If it detects changes, the report must be adapted to prevent errors. The program displays the Map Fields dialog box when it detects either of these types of changes to the database:
- The name of a database field that is used in the report has changed
- The database has been upsized from a PC data source to an SQL data source.
Crystal Reports automatically adapts the report (and does not display the Map Fields dialog box) if it detects any of these changes:
- Fields have been added to the database
- Fields that are not used in the report have been deleted from the database
- Field positions have changed in the database
- Data types have changed for fields in the database.
Using the Verify on Every Print process
Verify on Every Print triggers the Verify Database command every time you print your report.
- If there is a check mark beside Verify on Every Print, the option is active. It triggers Verify Database every time you print.
- If there is no check mark beside it, the option is inactive. The option is inactive by default.
Link
Edit MY goal is this, I need to do read data from a Remedy Database using a VB .Net app. /Edit
I am trying to read data from the AR System ODBC driver in a VS 2010 VB windows form.
I have added a connection in the data connections via , a system dsn, connection string pulled from a working excel data pull, and built a connection string based via the wizard.
I can test connection, and it comes back 'test connection succeeded'.
When I click ok and the Data connection goes to my server explorer, it expands to tables, view, and procedures and viewing/refreshing those causes errors such as:
Column 'Table_Cat' does not belong to table Tables.
Error [im00][ar system odbc driver] not supported
I am aware there is the api out there, however this has a problem in that the api acts like a login session from the client, which limits you to one login session. This not feasible for the task at hand as the user needs to remain logged into remedy, and the app I'm writing will be read only for data.
The goal is a billboard app that will display certain tickets, kind of like a stock ticker.
There will be no editing of ticket data from remedy, I just need to read the tickets and provide tallies and alerts for our helpdesk.
It seemed so easy when I sat down, but now 4 hours later and a mind numbing amount of irrelevant google results, I'm almost wondering if I'm going to have to report back that it cannot be done with out the api and creating more remedy accounts. Not having to create additional remedy accounts was part of of the request put to me.
Tags: Visual Studio 2010 BMC AR System Remedy ODBC VB.NET
Update
So I have done the code by hand and now seem a few steps forward, but still blind.
Ok, so if i export my excel query it looks like this from the dqy file
export.dqy
DRIVER={AR System ODBC Driver};ARServer=xxxxxx;ARServerPort=xxxxx;UID=xxxx;PWD=xxxx;ARAuthentication=;SERVER=NotTheServer
SELECT "EN:HelpDesk"."Company Name", "EN:HelpDesk"."Call Status", "EN:HelpDesk"."Caller Region", "EN:HelpDesk"."Next Action", "EN:HelpDesk"."Detailed Description(FTS)", "EN:HelpDesk".Device, "EN:HelpDesk"."Submitted-by", "EN:HelpDesk".Impact, "EN:HelpDesk"."Arrival Time", "EN:HelpDesk"."Call Id", "EN:HelpDesk".Market FROM "EN:HelpDesk" "EN:HelpDesk" WHERE ("EN:HelpDesk"."Call Status"<>'Closed') AND ("EN:HelpDesk"."Submitted-by"<>'nis') AND ("EN:HelpDesk".Impact='High') AND ("EN:HelpDesk".Market='DCIN') AND ("EN:HelpDesk"."Caller Region"<>'UK')
First off, these quotes look wrong to me, but it seems to work because if I leave them, executing the command doesn't fail, however it doesn't return data to my data grid view in vb.
Second the EN:Helpdesk looks odd to me but again same results as the quotes.
I have tried changing the quotes to brackets [ ] but receive errors once I do.
Here is my code:
VB Code
Imports SystemM My goal
Imports System.Data
Imports System.Data.Odbc
Imports System.Data.SqlClient
Sub Main()
Dim sql As String
Dim connectionString As String = "DRIVER={AR System ODBC Driver};ARServer=xxx;ARServerPort=xxx;UID=xxx;PWD=xxx;ARAuthentication=;SERVER=NotTheServer"
sql = "SELECT ""EN:HelpDesk"".""Company Name"", ""EN:HelpDesk"".""Call Status"", ""EN:HelpDesk"".""Caller Region"", ""EN:HelpDesk"".""Next Action"", ""EN:HelpDesk"".""Detailed Description(FTS)"", ""EN:HelpDesk"".Device, ""EN:HelpDesk"".""Submitted-by"", ""EN:HelpDesk"".Impact, ""EN:HelpDesk"".""Arrival Time"", ""EN:HelpDesk"".""Call Id"", ""EN:HelpDesk"".Market FROM EN:HelpDesk WHERE (""EN:HelpDesk"".""Call Status""<>'Closed') AND (""EN:HelpDesk"".""Submitted-by""<>'nis') AND (""EN:HelpDesk"".Impact='High') AND (""EN:HelpDesk"".Market='DCIN') AND (""EN:HelpDesk"".""Caller Region""<>'UK')"
Dim bindingSource1 As New BindingSource()
Me.SQLDS_reportresults.DataSource = bindingSource1
Dim myAdapter = New OdbcDataAdapter(sql, connectionString)
Dim commandBuilder As New OdbcCommandBuilder(myAdapter)
Dim table As New DataTable()
table.Locale = System.Globalization.CultureInfo.InvariantCulture
myAdapter.Fill(table)
bindingSource1.DataSource = table
Me.SQLDS_reportresults.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader)
End Sub
Project is a windows forms with a button to activate main(), a textbox (textbox1) and a datagridview(SQLDS_reportresults).
As the code stands, this causes no errors, but my datagridview never populates. Since there are no errors, I'm inclined to think my connection is working , and that my command is being executed,making my problem lay in code, however given the funky use of quotes and en:helpdesk in the sql command, I'm also concerned that is malformed and causing the where portion to return no results.
Anyone have any suggestions / ideas?
I need a way to display these results in app, and right now I don't care how just as long as I can see some data at all.
I've been googling and looked at the vb examples in the api zip but that is not related to opening a odbc connection and I found that of little help in my research.
I almost feel like I'm missing something simple or obvious.
When i run odbcad32.exe my ar system odbc driver shows 7.00.01.02 which is what I assume is installed on everyones machines as I used the remedy install set provided to me by the IT/Software admins to build this dev box.