Re: SQL Server Connection Declearation

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Douglas J. Steele (NOSPAM_djsteele_at_NOSPAM_canada.com)
Date: 10/09/04


Date: Sat, 9 Oct 2004 05:14:24 -0400

You need to set a reference to ADO.

Alternatively, you could use late binding, and replace

   Set cn = New ADODB.Connection

with

   Set cn = CreateObject("ADODB.Connection")

Of course, if you don't have a reference set to ADO, then your program won't
know the value of intrinsic constants (such as adUseServer, which you use
near the end). That means you'll either have to use the actual value of the
constant (2 in this case), or else define the constants to the program.

-- 
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
"Melvin.Ding" <melvin.ding@photoptech.com> wrote in message
news:epJ3LcdrEHA.4004@TK2MSFTNGP10.phx.gbl...
> Hello,
>
> I just tried to build a database connection from vb6.0 to SQL Server 8.0
to
> perform a simple query. See the codes below:
>
> Private Sub cmdSearch_Click()
>
>    Set cn = New ADODB.Connection
>    connstr = "Data Source=OPEN_VIEW;User=sa;Password=;"
>    cn.Provider = "SQLOLEDB"
>    cn.ConnectionString = connstr
>    cn.Open
>    cn.DefaultDatabase = "employee"
>    sql = "Select * from employee"
>    Set rs = New ADODB.Recordset
>    Set rs.ActiveConnection = cn
>    rs.CursorLocation = adUseServer
>    rs.Open sql, cn, adOpenKeyset, adLockOptimistic
> End Sub
>
> When I compiled the codes, IDE shows that "ADODB.Connection" is unknown
> user_define variable data type. So what are the steps I should take to
make
> the declearation "Set cn = New ADODB.Connection" valid?
>
> thanks.
>
>


Relevant Pages

  • Re: (VB6) Question about DataEnvironment, Please correct this code
    ... I wrote these codes, but seems like there are not correct. ... Private Sub Command1_Click ... txtAddress= .Fields.Value ... Using Google to search for "ADO Find Method" returned over a million hits. ...
    (microsoft.public.vb.general.discussion)
  • Re: Luddites ! ; forward into the past ! (ADO/DAO)
    ... I am the harbinger of doom for those who continue to try to use traditional ADO with .NET. ... ' Dim Conn As New ADODB.Connection ... Dim sql As String ... Private Sub Button1_ClickHandles Button1.Click ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Compile problem
    ... Dim db As DAO.Database ... Dim MyRs As DAO.Recordset ... especially if you've also got a reference set to ADO. ... An object named Recordset exists in both the DAO and ADO models, ...
    (microsoft.public.vb.database.dao)
  • Making the move from DAO to ADO, Seek does not work
    ... I'm making my first transition from DAO to ADO on one of my projects and am ... Private Sub Form_Load ... Set txtBurnHours.DataSource = adoCustomerRS ...
    (microsoft.public.vb.database.ado)
  • Re: newbie - get memory error message when close .exe
    ... private sub form_unload ... I am using the MSFLex grid data control, ado, and access 2000. ... But I have in form unload ...
    (microsoft.public.vb.general.discussion)