Type ADODB.Connection is not defined?-VBForums
Results 1 to 9 of 9

Thread: Type ADODB.Connection is not defined?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2007
    Posts
    9

    Type ADODB.Connection is not defined?

    Hi all. Im a Delphi programmer by trade but I recently got a copy of Visual Studio 2005 so I could write some applications for PDAs.

    Anyway, Im trying to connect to a MS SQL Server with ADO, and all the help Ive read tells me to do something like this :

    Public Class Form1
    Dim ADOCon As New ADODB.Connection

    But I get an error saying Type ADODB.Connection is not defined

    Any help would be much appreciated.
    Thanks

  2. #2
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Type ADODB.Connection is not defined?

    Welcome to VBF !

    I think you need to include a reference to the ADODB object into your project...(I use this method in classic vb, not sure in vb 2005)
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
    http://ganeshmoorthymc.com

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2007
    Posts
    9

    Re: Type ADODB.Connection is not defined?

    Yeah, Im not sure where though, or how really.

    That line of code I included
    Code:
    Public Class Form1
    is the very first line.

  4. #4
    Frenzied Member
    Join Date
    Aug 2005
    Posts
    1,042

    Re: Type ADODB.Connection is not defined?

    Nekron:

    I think maybe this is what you need:
    The following code creates a SqlConnection object, sets the
    SqlConnection.ConnectionString property, and opens the connection.
    VB Code:
    1. Public Sub ConnectToSql()
    2.     Dim conn As New SqlClient.SqlConnection
    3.     ' TODO: Modify the connection string and include any
    4.     ' additional required properties for your database.
    5.     conn.ConnectionString = & _
    6.     "integrated security=SSPI;data source=SQL Server Name;" & _
    7.     "persist security info=False;initial catalog=northwind"
    8.     Try
    9.         conn.Open()
    10.         ' Insert code to process data.
    11.     Catch ex As Exception
    12.         MessageBox.Show("Failed to connect to data source")
    13.     Finally
    14.         conn.Close()
    15.     End Try
    16. End Sub

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    37,027

    Re: Type ADODB.Connection is not defined?

    Just to explain why AIS4U's example is what you should be using.. ADODB is the 'old' version which is designed for Classic VB (VB6 and earlier), whereas ADO.Net (as in that example) is designed for VB.Net (VB 200*).

  6. #6

    Thread Starter
    New Member
    Join Date
    Jan 2007
    Posts
    9

    Re: Type ADODB.Connection is not defined?

    Ok, thanks people.

    I tried AIS4U's suggestion, and this is the declaration I had to make :

    Code:
    Dim Con As New System.Data.SqlClient.SqlConnection
    Does anyone know why I had to do this? Seems too long-winded, but necessary unfortunately.

    Also, is it possible to prompt for a Connection String at run-time? I was thinking, you know how you go through the wizard, and it prompts you to select a server, enter username and password, and select a database, is it possible to do this at run-time?

    Thanks all.

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    37,027

    Re: Type ADODB.Connection is not defined?

    The ConnectionString is just a string in a particular format, so you can simply put in the relevant parts (like "SQL Server Name") using code which gets the values from a form (or anywhere you like!).

  8. #8
    New Member
    Join Date
    Feb 2009
    Posts
    6

    Re: Type ADODB.Connection is not defined?

    i'm using visual basic 2008 express edition. i get that problem also. i need to export datagrid to excel. instead of ADODB.Connection, can i use Odbc.OdbcConnection()?

  9. #9
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    37,027

    Re: Type ADODB.Connection is not defined?

    You should not be using ADODB at all, as that is designed for VB6 (aka VB1998) and earlier.

    Instead, you should be using ADO.Net (for VB2002 and later, aka VB.Net), which includes SqlConnection/OLEDBConnection/ODBCConnection.

    In addition to AIS4U's example, you can find lots of useful info in the VB.Net section of our Database Development FAQs/Tutorials (at the top of this forum)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.