Thank you in advanced for your help.
I am new in this site.
I need to create a procedure to export .rpt to pdf. I am using parameters in .rpt because i am using sql stored procedure to create the report.
I am developing in asp.net 2008 with vb.
Regards.
I resolved my question.
This is the code, because if you need it.
Regards.
Dim PathFile As String = "c:\Documents" & "\Reporte.pdf"
formatType = ExportFormatType.PortableDocFormat
Dim oConexInfo As New CrystalDecisions.Shared.TableLogOnInfo
oConexInfo.ConnectionInfo.ServerName = "SERVER"
oConexInfo.ConnectionInfo.DatabaseName = "DBNAME"
oConexInfo.ConnectionInfo.UserID = "USERID"
oConexInfo.ConnectionInfo.Password = "PASSWORD"
rpt.Load(Server.MapPath("~/Imprime.rpt"))
rpt.SetParameterValue(0, Val(txt_No_Quotation.Text)) ' I send a parameter value
rpt.Database.Tables(0).ApplyLogOnInfo(oConexInfo) ' Here I send the credentials for conection to SQL Server with crystal reports
CrystalReportViewer1.ReportSource = rpt
ConfigureCRTSTALREPORT()
rpt.ExportToDisk(formatType, PathFile) ' Here I export the pdf to disk (in server side)
Related
I'm currently troubleshooting some old code that simply serves up a file from a file share, and can't figure out why the SQL query is not returning what I expect from an Oracle database.
Here you can see the database entry for the file I'm trying to download:
And here is what the below javascript alert returns:
You can see that the Fields(index).value call below is returning the above value. It seems to be escaping the backslashes, how can I resolve?
dim goCon
set goCon = Server.CreateObject("ADODB.Connection")
dim gsSQL
'Define SQL here to query database and return frtFileName
set goRSet = goCon.Execute(gsSQL)
if goRSet.EOF then
Err.Raise 1,Request.ServerVariables("URL"), "Invaild Report ID"
else
gsFileName = goRSet.Fields("frtFileName").value
Response.Write "<script type='text/javascript'>alert('gsFileName:" & gsFileName & "');</script>"
I created a report using report document object model in visual studio 2008 with vb.net. But I found one error. When the user clicks export button in client side, the following error will show. But the first time is OK before the user clicks export button.
Logon failed. Details: ADO Error Code: 0x Source: Microsoft OLE DB Provider for SQL Server Description: Login failed for user 'zanhtet'. SQL State: 42000 Native Error:
This is calling report code.
Dim ReportDocument As New ReportDocument()
Dim ReportPath As String = Server.MapPath("~/ReportDocumentOM/DBlogInRDOM.rpt")
ReportDocument.Load(ReportPath)
ReportViewer.ReportSource = ReportDocument
Dim ConnectionInfo As New ConnectionInfo
ConnectionInfo.ServerName = "ZANHTET\SQLEXPRESS"
ConnectionInfo.DatabaseName = "EAS_DevTrack4UDev"
ConnectionInfo.UserID = "zanhtet"
ConnectionInfo.Password = "123456"
For Each Table As Table In ReportDocument.Database.Tables
Dim TableLogOn As TableLogOnInfo = Table.LogOnInfo
TableLogOn.ConnectionInfo = ConnectionInfo
Table.ApplyLogOnInfo(TableLogOn)
Next
How can I solve this. Please, help me.
I am not sure your code above is invoked at what place. But if you are not already doing this, then handle important events from reportviewer. Inside those event handling method, make sure you invoke this authentication code again.
Export related event should do you a luck but you may have to handle couple of others as well (like for pagination also i had similar issues).
See here for Report Viewer Events
http://msdn.microsoft.com/en-us/library/microsoft.reporting.winforms.reportviewer.reportexport.aspx
I am Publishing crystal reports on remote server using the following code. when i try to run the crystal report page Crystal report viewer prompt me for database info. As the published crystal report were created using development server. In my crystal report i was using OLEDB ADO Connection
MyRepository _MyRepository = new MyRepository();
System.Data.SqlClient.SqlConnection myConnection = new System.Data.SqlClient.SqlConnection();
myConnection.ConnectionString = ConfigurationManager.ConnectionStrings["MyConnStr"].ConnectionString;
System.Data.SqlClient.SqlCommand MyCommand = new System.Data.SqlClient.SqlCommand("dbo.spMySP");
MyCommand.Connection = myConnection;
MyCommand.Parameters.Add("#PositionID", SqlDbType.Int).Value = (cmbPositions.SelectedValue == "" ? 0 : Convert.ToInt32(cmbPositions.SelectedValue));
MyCommand.CommandType = System.Data.CommandType.StoredProcedure;
System.Data.SqlClient.SqlDataAdapter MyDA = new System.Data.SqlClient.SqlDataAdapter();
MyDA.SelectCommand = MyCommand;
ASale _DS = new ASale();
MyDA.Fill(_DS, "dbo.spMySP");
rptSale oRpt = new rptSale();
oRpt.SetDatabaseLogon("sa", "mypass");
oRpt.SetDataSource(_DS);
oRpt.SetParameterValue(0, "param1");
oRpt.SetParameterValue(1, "param2");
oRpt.SetParameterValue(2, "param3" );
oRpt.SetParameterValue(3, (cmbPositions.SelectedValue == "" ? 0 : Convert.ToInt32(cmbPositions.SelectedValue)));
CrystalReportViewer1.ReportSource = oRpt;
HI,
When you develop your report, do you use Windows authentication to login to the database to build the report?
Maybe you can try to open the report again and try to update your database set up on the crystal report. E.g. by using the same login information your use on your code.
What I normally do is to put the database server name and the database name on to the code as well
E.G.
_CReportDoc.SetDatabaseLogon(username, pw, ServerName, DB)
Not sure if it could help
I'm using crystal reports to build reports, everything is ok while development.
But after deployment of website, print functionality doesn't work.
I use _rptDocument.PrintToPrinter(1, false, 0, 0); to print report.
I've tried two methods to deploy website
Normal Publish option.
Web Deployment Project.
But I got the same output, print functionality doesn't work.
Also, I tried to set default printer, this also doesn't work.
Any ideas?
Printing on a web server isn`t a good idea. What should happen? A user prints on your servers printer? Use CR to create PDFs. Stream them to your clients. They can use their local printers.
try this :- Create PDF and open Browser Tab ...enter code here
string fname = "Report" + ".pdf";`enter code here`
//Create instance for crystal report Export option class
ExportOptions exprtopt = default(ExportOptions);
//create instance for destination option - This one is used to set path of your pdf file save
DiskFileDestinationOptions destiopt = new DiskFileDestinationOptions();
//Bind data in the crystal report first before export cystal report to PDF
ReportDocument RptDoc = new ReportDocument();
//Map your crystal report path
// RD.Load(Server.MapPath("~/CrystalReport2.rpt"));
//Set your crystal report datasource as dt
//Get path and assign into destination DiskFileName
destiopt.DiskFileName = Server.MapPath(fname);
exprtopt = RD.ExportOptions;
exprtopt.ExportDestinationType = ExportDestinationType.DiskFile;
//use PortableDocFormat for PDF data
exprtopt.ExportFormatType = ExportFormatType.PortableDocFormat;
exprtopt.DestinationOptions = destiopt;
//finally export your report document
RD.Export();
//To open your PDF after save it from crystal report
string Path = Server.MapPath(fname);
//create instance to client to open your pdf
WebClient client = new WebClient();
//Assign path to download pdf
Byte[] buffer = client.DownloadData(Path);
//metion content type as PDF and write
// Response.ContentType = "application/pdf";
//Response.AddHeader("content-length", buffer.Length.ToString());
//Response.BinaryWrite(buffer);
//======================================
Response.Write("<script>");
Response.Write("window.open('" + fname + "', '_newtab');");
Response.Write("</script>");
//===================================
IMTIYAZ
Is there any way to export data (not necessarily schema) to an access database via asp.net?
The server has no office components installed and the process must occur via a webpage (like an excel export).
You have to do it programatically.
Open the source table
Create a new AccessDB using ADO Extensions (as shown above)
Create the table in the AccessDB by reading the source schema (CREATE TABLE X ...)
Iterate thought the source table inserting the records in the Access table
Note: Code from http://www.freevbcode.com/ShowCode.asp?ID=5797 posted here in case the link cease to exists in the future
'select References from the Project Menu, choose the COM tab,
'and add a reference to Microsoft ADO Ext. 2.7 for DDL and Security
Public Function CreateAccessDatabase( ByVal DatabaseFullPath As String) As Boolean
Dim bAns As Boolean
Dim cat As New ADOX.Catalog()
Try
'Make sure the folder
'provided in the path exists. If file name w/o path
'is specified, the database will be created in your
'application folder.
Dim sCreateString As String
sCreateString = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
DatabaseFullPath
cat.Create(sCreateString)
bAns = True
Catch Excep As System.Runtime.InteropServices.COMException
bAns = False
'do whatever else you need to do here, log,
'msgbox etc.
Finally
cat = Nothing
End Try
Return bAns
End Function
DEMO
====
' If CreateAccessDatabase("F:\test.mdb") = True Then
' MsgBox("Database Created")
' Else
' MsgBox("Database Creation Failed")
' End If
Here is a very detailed article. It is something I stumbled upon, not an approach I am familiar with:
File Uploading to Access Database using ASP.NET
by Faisal Khan.