an error of report document object model - asp.net

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

Related

SqlKata - I'm not understanding how Paginate works

I am a beginner using this library SqlKata, and I'm having hard time understanding the functionality of the Paginate method.
With the Get method, I can access the SQL records. But with Paginate I can not. Will the Paginate method bring me the records of the database?
dim db = new QueryFactory(new SqlConnection("[connection-string]"), new SqlServerCompiler())
dim library = db.Query("my_table").Select("*").Paginate(1, 10)
for each book in library.each
response.write(book.id)
next
This throws a error:
Public member 'id' on type 'PaginationResult(Of Object)' not found.
System information:
SqlKata 1.1.3
Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3163.0
VB.NET
It looks like the documentation needs an update.
Here's how I managed to use the pagination:
dim db = new QueryFactory(new SqlConnection("[connection-string]"), new SqlServerCompiler())
dim q = db.Query("my_table")
'Just if you need to know total of pages and other utilities
dim info = q.Paginate(1, 10)
'DB rows
for each book in info.list
response.write(book.id)
next
'If you do not need the pagination object, you can use:
'here we retrieve 10 records from page 2
for each book in q.ForPage(2, 10).Get()
response.write(book.id)
next

How to return a file from a ASP.Net API call?

I have read a number of answers, and been searching the web for the last few weeks to try and find an answer to this.
I have read: How to return a file (FileContentResult) in ASP.NET WebAPI
and: Returning binary file from controller in ASP.NET Web API
When I am debugging, it will just continuously callback, running the method over and over.
When running on a server (IIS), depending on the browser, there will be a message saying This site can’t be reached, or it will download the file, but indicate that the download has faield.
The code I am using is
<HttpGet, Route("api/Reports/Create")>
Public Function CreateReport() As HttpResponseMessage
Dim data = GetReportBuffer()
'This is just for testing
'To check that the report is created correctly
'I can open up temp.pdf, it is fine
Using fs As New FileStream("c:\temp\temp.pdf", FileMode.Create)
data.CopyTo(fs)
fs.Flush()
fs.Close()
End Using
Dim result = Request.CreateResponse(HttpStatusCode.OK)
'This should be StreamContent(data... but using this for testing
result.Content = New StreamContent(New FileStream("c:\temp\temp.pdf", FileMode.Open))
result.Content.Headers.ContentType = New MediaTypeHeaderValue("application/octet-stream")
result.Content.Headers.ContentDisposition = New ContentDispositionHeaderValue("attachment") With {.FileName = $"{fllId}.{ext}"}
Return result
End Function
I have also tries ByteArrayContent, but the result is exactly the same.
Is there anything I am not doing correctly?

Exception thrown when using GData .NET Analytics API

I am facing an issue while trying to fetch data from GoogleAnalytics API on piece of code that has been working well just a couple of days ago.
For this I am referencing the following DLL's:
Google.GData.Analytics.dll
Google.GData.Client.dll
Google.GData.Extensions.dll
And I am using the following code:
Dim visits As String = String.Empty
Dim username As String = "myuser#mydomain.com"
Dim pass As String = "mypassword"
Const dataFeedUrl As String = "https://www.google.com/analytics/feeds/data"
Dim query As AccountQuery = New AccountQuery()
Dim service As AnalyticsService = New AnalyticsService("MyWebAnalyticsService")
service.setUserCredentials(username, pass)
Dim accountFeed As AccountFeed = service.Query(query) ''----------> Exception thrown in this line: GDataRequestException Execution of request failed: https://www.google.com/analytics/feeds/accounts/default
I thought it had to do with a blocking to the account I was using but it wasn't the case because I verified registering the site for another analytics account and is still not working.
This code has been working flawlessly as I've said but all of a sudden has stopped doing so yesterday.
Could you please help me figuring out what's wrong?. Maybe the way the user credentials are set has changed and I am missing something.
Thank you very much for your help.
'----Update----
I managed to make it work and now I can query the visits for a desired domain. The code goes as follows:
Dim visits As String = String.Empty
Dim username As String = "myuser#mydomain.com"
Dim pass As String = "mypassword"
'Follow the instructions on https://developers.google.com/analytics/resources/articles/gdata-migration-guide (Create a Project in the Google APIs Console) to generate your key
'Once you have it set it as part of the querystring to request our GA service
Dim gkey As String = "key=yourkeystring"
'Set the new URI to retrieve the feed data and append it the generated key
Dim dataFeedUrl As String = "https://www.google.com/analytics/feeds/data?" & gkey
'Create and authenticate on our service instance
Dim service As AnalyticsService = New AnalyticsService("MyAnaliticsService")
service.setUserCredentials(username, pass)
'Use the profile id for the account you want to get ths visits from, you can find it
'logging in your analytics account, select the desired domain on your list (blue link)
click on the administrator button and on the profiles tab find the profile
'configuration subtab, right there you will find the profile id in this case the eight characters long id 12345678
Dim query1 As DataQuery = New DataQuery(dataFeedUrl)
With query1
.Ids = "ga:12345678"
.Metrics = "ga:visits"
.Sort = "ga:visits"
.GAStartDate = DateTime.Now.AddMonths(-1).AddDays(-2).ToString("yyyy-MM-dd")
.GAEndDate = DateTime.Now.ToString("yyyy-MM-dd")
.StartIndex = 1
End With
'Use the generated datafeed based on the former query to get the visits
Dim dataFeedVisits As DataFeed = service.Query(query1)
For Each entry As DataEntry In dataFeedVisits.Entries
Dim st As String = entry.Title.Text
Dim ss As String = entry.Metrics(0).Value
visits = ss
Next
I have the same problem and it looks like google recently shut down the feed. It is answered in another post. Issue com.google.gdata.util.ResourceNotFoundException: Not Found with Google Analytic
Please make sure you registered your project in the APIs Console and you are sending the API Key with your requests.
If that is not the issue, inspecting the inner exception will give you more details about the error. As an alternative, you can use Fiddler to capture the HTTP request and the response. The latter will include a more descriptive error message.

Crystal Reports- Export report causing "Missing Parameter Values"

I am trying to export a report but everytime it runs the code to export the crystal report in the crystalreportviewer I get an error message saying "Missing Parameter Values". I've looked through many sources but havent found a solution. I do know that all parameters are filled in because without the export code, the site runs perfectly fine.
Export code
Try
Dim CrExportOptions As CrystalDecisions.Shared.ExportOptions
Dim CrDiskFileDestinationOptions As New _
CrystalDecisions.Shared.DiskFileDestinationOptions()
Dim CrFormatTypeOptions As New CrystalDecisions.Shared.PdfRtfWordFormatOptions()
CrDiskFileDestinationOptions.DiskFileName = _
"c:\crystalExport.pdf"
CrExportOptions = oRpt.ExportOptions
With CrExportOptions
.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile
.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat
.DestinationOptions = CrDiskFileDestinationOptions
.FormatOptions = CrFormatTypeOptions
End With
oRpt.Export()
Catch ex As Exception
Response.Write(ex.ToString)
End Try
Also:
'Try
' oRpt.ExportToHttpResponse([Shared].ExportFormatType.PortableDocFormat, Response, True, "ExportedReport")
'Catch ex As Exception
' Response.Write(ex.ToString)
'End Try
Any help would be great.
This is caused under 2 reasons.
Either, you're not passing(from the program) a required parameter which you have created in the report.
Or, you're passing a parameter to the report but you haven't created it in the report.
To solve my own problem I found that the code actually exports the instance of the crystal report, whereas I was putting the parameters into the crystalreportviewer after providing the source. Instead I provided the parameters directly into the instance which gets pushed into the crystalreportviewer as a datasource.
:)
In my case, there was a subreport that was not correctly linked with the main report.
Check if all the parameters of the subreport is linked with the main report.
Cheers;
Have to set required parameters
Set rpt.SetDataSource(dt) even DataTable records count is 0:
DataTable dt = new DataTable();
dt.Load(data);
if (dt?.Rows != null)
{
rpt.SetDataSource(dt);
return true;
}

Why do we get "Path not found" error while accessing vb code from classic asp page?

Could you please give your suggestions to the below problem:
I am working on a old project which was developed using traditional ASP and VB6.0.
I have registered the dll in component services. After creating the object in first line (in the code snippet below), when trying to call Login() method, it is giving the "Path not found" warning/error and I am not able to continue executing it further.
Thanks in advance for your consideration and help...also please let me know if you need more information...
SET objSecurity = Server.CreateObject( Application("APP_CLASS") & "Security" )
SET ox = new XMLTool
userID = uCase(userID)
dataXML = ""
IF objSecurity.Login( sessXML, userID, pwd, datXML ) Then
ox.LoadXML dataXML
..........
..........
"Path not found" is usually an IO exception. Does the objSecurity.Login() method read or write any data to a file or directory that does not exist? What is happening inside the objSecurity.Login() method?
Alternately, is there another "benign" method of the objSecurity object that you can call to verify that the object lives? Something like:
Dim sTest As String = objSecurity.Version()
or
Dim sTest As String = objSecurity.Name()
or even
Dim bExists As Boolean = (objSecurity IsNot Nothing)
I know that .ToString() didn't exist in VB6, but that's the idea.
Let's narrow down the problem to either objSecurity object itself, or something inside the .Login() method.

Resources