Showing posts with label vb6. Show all posts
Showing posts with label vb6. Show all posts

Wednesday, March 28, 2012

Opening SqlConnection - VB.NET

I used to use rdo in VB6 and now I'm trying to figure out how to use the SqlDataReader class in VB.NET. I want to use an ODBC data source to specify the connection info. I used to give the rdoConnection object a connect string that looked something like this:
"DSN=[data source name];UID=[sql server user];PWD=[pwd]"
I don't understand the connect string given in all the examples I've found (nor does it seem to work on my system...)

mySqlConnection =New SqlConnection("server=(local)\VSdotNET;Trusted_Connection=yes;database=northwind")
Does anyone have any ideas? I'm open to explanations as well as solutions :)
Thanks,
jdm

Already tried to look at: http://www.connectionstrings.com/ ?|||jsmiller, are you receiving an error message?
Can you shell out to DOS (EDIT: i.e. acommand prompt, sheesh my age is showing), and run this command:
osql -L
This will tell you the name of the SQL Servers to which you haveaccess. Whatever is returned is what should go into the server=part of the connection string. If you are still having trouble,please paste your connection string and error message and we will tryto help you through it.
|||

Success! The thing is that I don't want to specify a server name but rather a System DSN... So I think based on a little more research (thanks connectionstrings.com), I don't want to use a sqlConnection but an odbcConnection. Here is my latest attempt:

Dim myOdbcConnectionAs OdbcConnection

Dim myOdbcCommandAs OdbcCommand

Dim myOdbcDataReaderAs OdbcDataReader

myOdbcConnection =New OdbcConnection("DSN=DSN;User Id=sa;Password=PWD")

myodbccommand =New OdbcCommand(SQLString, myOdbcConnection)

myOdbcConnection.Open()

myOdbcDataReader = myOdbcCommand.ExecuteReader(CommandBehavior.CloseConnection)
The program breaks on the myOdbcConnection.Open line, with an error
ERROR [28000] [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection.
So if I add "Trusted_Connection=true" to the connect string everything seems to work out. At this point, my question is what does the trusted connection variable really mean? Am I making a security mistake?
I'm new to this so any comments welcome.
Thanks!
jdm

Tuesday, March 20, 2012

Open printer dialog in runtime mode in VB6

Hay,
when i open report from visual basic 6 using viewer its give me only printer icon which only print direct to deafult printer without any option to choose another printer.
How i can choose which printer i want in runtime in VB6If found this:

Report.PrinterSetup 0
Report.PrintOut

But for me it was easier to create my own Printer Selection form. I added a combobox for the Printer (filling it by looping through the Printers Collection), option buttons for All Pages or a specific page range, and a spinner for number of copies. I also added properties to the SelectPrinter Form to hold the data. Once the user picks the options and clicks 'Print', VB send the data to Crystal's .Printout.

Private Sub CRViewer_PrintButtonClicked(useDefault As Boolean)

Dim cOrientation As CRPaperOrientation
Dim cSize As CRPaperSize

useDefault = False

'Capture the original Orientation and Paper Size,
' SelectPrinter resets Landscape to Portrait
cOrientation = Report.PaperOrientation
cSize = Report.PaperSize

'Reset Form and all data by calling the NewData function on the SelectPrinter Form
frmSelectPrinter.NewData

'Set Max Number of Pages
frmSelectPrinter.MaxPages = Report.PrintingStatus.NumberOfPages

'Show Form and wait for User
frmSelectPrinter.Show vbModal

If Len(frmSelectPrinter.DeviceName) > 0 Then
'If a device is selected, print report
Report.SelectPrinter frmSelectPrinter.DriverName, _
frmSelectPrinter.DeviceName, frmSelectPrinter.Port

'Set the Orientation and Paper Size to the original,
' SelectPrinter resets Landscape to Portrait
Report.PaperOrientation = cOrientation
Report.PaperSize = cSize

Report.PrintOut False, frmSelectPrinter.Copies, , _
frmSelectPrinter.FromPage, frmSelectPrinter.ToPage


End If

End Sub