Click here to Skip to main content
15,029,501 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,
I try to create report using Crystal report viewer 9 ,MS SQL and VB6. I designed the report using OLE DB(ADO) connection. I connect one table. My code is,
Option Explicit
Dim Appl As New CRAXDRT.Application
Dim Report As New CRAXDRT.Report

Private Sub Print_Click()

   Set Appl = New CRAXDRT.Application
   Set Report = Appl.OpenReport(App.Path & "\Bill1.rpt")
   
   Set rs = New ADODB.Recordset
   
   strReso = "SELECT BI_BILLNO,IM_Description,IM_SPrice,BI_QUANTITY,BI_AMOUNT " + _
   "From BILLITEM,ITEMMASTER Where BI_BILLNO = " + Trim(txtBillNo.Text) + _
   " and BI_ITEMCODE = IM_ItemCode"
   rs.Open strReso, conMain, adOpenStatic, adLockReadOnly
   
   Report.DiscardSavedData
   Report.ParameterFields.GetItemByName("BillNo").AddCurrentValue txtBillNo.Text
   Report.Database.SetDataSource rs
   
   CRViewer91.ReportSource = Report
   
   CRViewer91.ViewReport

End Sub

Connection String is "str1 = "Provider=SQLOLEDB.1;User ID = hemantha; Password=19760207;Initial Catalog=Waruni_Sale_System;Data Source=""

It is working. But, when I used two tables, occur a error message as
"Logon Failed,Deiails: Ado Error code 0x80040e4d, Sorce: Microsoft OLEDB Provider for SQL Server, Description: Login failed for user 'User Name', SQL State: 42000, Native Error:18456".
The report is working in Crystal Report( "Preview").
What is the wrong? Anyone can help?

What I have tried:

I try to print a bill using Crystal report viewer 9, VB6, MS SQL 2000.
Posted
Updated 6-Jan-21 20:23pm
Comments
CHill60 17-Jul-18 7:17am
   
It hasn't got anything to do with the number of tables, you are not connecting to the database properly and you haven't shown use the code where you actually connect.
I don't think there should be spaces on either side of the = for the User ID - worth a try. And it's also worth trying to log on with SSMS with those details.
Beyond that you are exposing yourself to SQL Injection attacks - don't use string concatentation to create sql statements.
Finally, you should not be writing new code in VB6 - it went out of support decades ago.
PLAA Hemantha 17-Jul-18 8:52am
   
Thanks for your reply, Please can you send some simple project.
CHill60 17-Jul-18 10:53am
   
No I'm afraid I can't. I avoiding using Crystal Reports as much as humanly possible and stopped using VB6 several years ago. I don't have a copy of it and I'm not going to fork out money for VB6 when I can just download VB.NET for free.
Did you remove the spaces as I suggested?
Can you connect via SSMS as I suggested?
#realJSOP 17-Jul-18 7:17am
   
I would tell you to stop using Crystal Reports, but since you're also using VB6, I figure you'll just ignore me.
PLAA Hemantha 17-Jul-18 8:47am
   
Thanks Mr.John,
Actually, I used Data Report. But, I had to face a problem couldn't solve. I want to set leftmargin set to 0 of Data Report. I asked help,I didn't find a solution.See "http://www.vbforums.com/showthread.php?762425-not-set-left-margin-in-printer-please-help-quick" Post 17 and 20. I'm using thermal bill printer. When Post #2 code is used, left margin size is 5mm. But it is 10mm. when I use Data Report and POS machine, can not adjust left margin size to 5mm(on paper. it is viewing as 0 margin on PC). But other all times ( Data Report with other printer, Post #2 code or any other document with POS machine), can adjust left margin size to 5mm. How can I solve this? Please help.
#realJSOP 17-Jul-18 9:17am
   
You misunderstand - I'm not interested in helping you with this problem. I'm just here to be a smartass...

1 solution

Dynamically you need to pass logon info in your code. Before that, you might want to refresh your report in design view.
C# Crystal Reports Dynamic Logon parameters[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900