Hi! can anybody pls. help me. How Can i connect my VB6 Application to Sql server? is it posible to connect my VB6 application directly to sql server without any requirements in the client? thanks in advance!!!
Private mobjConnect 'The object containing the connection.. declare it at whatever level you need.
' or you could specifically type it so you can see all the properties and
' methods assciated with in VBPrivate mobjConnect As ADODB.Connection
'These are the variables you'll need for connection or if you're a savage
' you can hard code them in to the method.
Private DB_NAME As String
Private SERVER_NAME As String
Private DB_USER As String
Private DB_PASS As String
Then as a property in the db class or just create it as a standard function:
Friend Property Get dbConnect() As Variant
'Private function GetdbConnect as variant
'Attempt to get a connection object.
If mobjConnect = Empty Or Not IsObject(mobjConnect) Then
' Don't check if there was an error
'Let the error permeate back to the calling object to report the error.
Set mobjConnect = CreateObject("ADODB.Connection")
'or use Dim objTmpConnect As New ADODB.Connection
mobjConnect.ConnectionTimeout = 90
If mbolWinAuth Then
mobjConnect.ConnectionString = "Provider=SQLOLEDB" + ";SERVER=" + SERVER_NAME + ";DATABASE=" + DB_NAME + _
";Trusted_Connection=Yes;APP=MyApp" & App.Major & "." & App.Major & "." & App.Revision
'Use application or client defined
mobjConnect.ConnectionString = "Provider=SQLOLEDB" & ";SERVER=" & SERVER_NAME & ";DATABASE=" & _
DB_NAME & ";User ID=" & DB_USER & ";Password=" & DB_PASS
' open connection
Set dbConnect= mobjConnect 'Return ref to connection object
So you then have this dbConnect object (or a reference to it) that you can use to execute SQL/sp's:
Set objRS = CreateObject("ADODB.Recordset")
Set objRS = dbConnect.Execute("Select blah from blah")
If Not objRS.EOF Then
??? = objRS.GetRows
??? = objRS.Fields("column_Name").Value
Thats basically it...
Some days you're the bug, some days you're the windscreen.