Error 20599 in vb

I am getting this error while i'm trying to set the connection string of crystal report the error msg is error '20599' Cannot open SQL server.

Actually I have met this problem long time ago, but I have choose to avoid it by doing crp.connect="PWD="
Well, in the end i still need to programmatically set my connection string, my original setting is like


May I know is there anything wrong with this, cos i keep getting this error, and I am sure that all the parameter is correct because i have successfully use same parameter to do my database connection for ADODB connection which is

"Provider=SQLOLEDB.1;Persist Security Info=False;" & _
                           "User ID=sa;password=ttnika;" & _
                           "Initial Catalog=Shipping" & ";Data Source=ADRIAN"

So, any expert out there please help me, cos i'm desperate searching the internet whole day and find no solution.

Secondly, I would like to know also, how can I programmatically use vb syntax to set the printer for crystal report?


Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Instead of passing provider setup you can use this syntax

Report.database.setdatasource recordset,3,1  
and for printer setup you can pop up the printer window by giving this command
report.printersetup true

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
biao81Author Commented:
I solve the error open sql server, it's actually a careless mistake whereby i put my DSN name wrongly. well for report.printersetup,
it's actually report.printerselection, it works, so i think i will give the point to yaday_surrender for the printer part. but before this,
can u teach me how to pop up the printerselection only when user click on the little print button, cos currently, mine pop up whenever i
view a report even b4 i click on print.

what i do now is

anyone pls advises
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

To avoid the printer setup screen showing before you click the print button, put the code in the print button click event not in the code that calls the report.

biao81Author Commented:
what is the name of the event then? i couldn't find it
I believe it is PrintButton_Click

I don't have an appropriate CR & VB here to check it.

What code are you using to call the report?

What method OCX, RDC?

biao81Author Commented:
I believe there is no such event.

I am using OCX
Sorry missed the .action = 1 which is the OCX.  You are correct the OCX doesn't have events.

As I recall the OCX has a PRINTERSELECTION button.  Enable that and tell the user to click it first, just as you have to from WORD with FILE--> PRINT rather than hitting the print button.

If it is not solved your problem of printer selection then you can use this way:
First take a common dialog control with components.  Name it DlgCmd
write button_click event
on error resume next
printer.setdefault=true  'For default printer
DlgCmd.flag=&H8 or &H100000

'Common dialog control is under projects->components->Microsoft Common controls

I am getting this error while i'm trying to set the connection string of crystal report the error msg is error '20599' Cannot open SQL server.
Crystal Report  version is 8.5.

The following is the code written in VB

CrystalReport1.ReportFileName = "c:\report1.rpt"
CrystalReport1.Connect = "Provider=sqloledb;Data Source=;Initial Catalog=HerbalAdvisor;User ID=sa;Password=z4327928sIERRA99;"
    CrystalReport1.DiscardSavedData = True
    CrystalReport1.Action = 1

Can anybody help regarding this problem its very urgent.

biao81Author Commented:
hey, sr_haneef. initially this is the problem i post in this topic, but sounds like now I'm the one trying to help u, LOL.
You can try this, open ur report with crystal report itself. On the Menu, go to Database --> Set Location, and then for every table in the database,
remove the prefix of the table eg. if you see dbo.TableName, make it TableName. Remember to do it for every table. then click Done.
Save ur work, and it should solve ur problem.
It is generally expected for you to open your own questions.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.