Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Connection

Connection

Scheduled Pinned Locked Moved Visual Basic
question
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    What Am I doing wrong? I am getting the message object is close Dim objcnn1 As New ADODB.Connection Dim objcmd1 As New ADODB.Command Dim objrst1 As New ADODB.Recordset Dim str As String Dim GConnection As String objcnn1.Open "Provider=MSDASQL.1;password =;User Id = ;Data Source=TEST;" objcmd1.ActiveConnection = objcnn1 With objrst1 .ActiveConnection = objcnn1 .CursorType = adOpenDynamic End With sDownload = "SELECT * FROM test " objrst1.Open sDownload Do While Not objrst1.EOF MsgBox " " & sDownload objrst1.MoveNext Loop

    L M 2 Replies Last reply
    0
    • A Anonymous

      What Am I doing wrong? I am getting the message object is close Dim objcnn1 As New ADODB.Connection Dim objcmd1 As New ADODB.Command Dim objrst1 As New ADODB.Recordset Dim str As String Dim GConnection As String objcnn1.Open "Provider=MSDASQL.1;password =;User Id = ;Data Source=TEST;" objcmd1.ActiveConnection = objcnn1 With objrst1 .ActiveConnection = objcnn1 .CursorType = adOpenDynamic End With sDownload = "SELECT * FROM test " objrst1.Open sDownload Do While Not objrst1.EOF MsgBox " " & sDownload objrst1.MoveNext Loop

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      :cool: as such you are using the MSDASQL provider u r here not specifying the path of the source :-O i think that u should specify the path of the source else wise he will take the application path also u r using the MSDASQL provider then i think that you have to login the SQL server to access the database i m not sure abt it :~ check whether the objcnn1 is open or not and get the error from err.number first do the connection and then do the rest of the things with that object :laugh: :cool: VickyMD A Specialist in Message Digest Security

      1 Reply Last reply
      0
      • A Anonymous

        What Am I doing wrong? I am getting the message object is close Dim objcnn1 As New ADODB.Connection Dim objcmd1 As New ADODB.Command Dim objrst1 As New ADODB.Recordset Dim str As String Dim GConnection As String objcnn1.Open "Provider=MSDASQL.1;password =;User Id = ;Data Source=TEST;" objcmd1.ActiveConnection = objcnn1 With objrst1 .ActiveConnection = objcnn1 .CursorType = adOpenDynamic End With sDownload = "SELECT * FROM test " objrst1.Open sDownload Do While Not objrst1.EOF MsgBox " " & sDownload objrst1.MoveNext Loop

        M Offline
        M Offline
        mikasa
        wrote on last edited by
        #3

        First, you're using some bad programming techniques that will lead to some overhead in the Code. Anytime you Declare a Variable with the "...As New" and it's an Object, then every time you set a Property or use a Method, the VB Compiler ALWAYS checks to see if the Object has been instantiated...this is some significant overhead if you use this routine a lot. Actually, it looks like the whole Connection String is wrong... The Provider "MSDASQL" is strictly used for DataSources that reside in the ODBC DataSources. If this is the Case, and you do not have a User / Password, then leave those Parameters out. Also, do not put a SemiColon at the end of the Connection String. Also, why did you make an "ADODB.Command" Object if you never used it?? NOTE: Also, you better learn the difference between Dynamic, ForwardOnly, Static, and Keyset cursors before you program any further, you are not making the most efficient use of resources...

        Dim adoCon As ADODB.Connection
        Dim rsData As ADODB.Recordset
        
        'Open the Connection
        Set adoCon = New ADODB.Connection
        'objcnn1.Open "Provider=MSDASQL.1;password =;User Id = ;Data Source=TEST;" (Wrong)
        adoCon.Open "Provider=MSDASQL.1;Data Source=TEST"
        
        'Open the Recordset
        'Open ForwardOnly / ReadOnly because we are only Enumerating the Records (maybe filling a ComboBox)
        Set rsData = New ADODB.Recordset
        rsData.CursorLocation = adUseClient
        rsData.Open "Select * From Test", adoCon, adOpenForwardOnly, adLockReadOnly, adCmdText
        
        While (Not rsData.EOF)
             MsgBox " " & rsData.Fields(0).Value 'sDownload (Huh?)
             'MsgBox " " & rsData.Fields("FieldName").Value
             'MsgBox " " & rsData!FieldName
             'MsgBox " " & CStr(rsData!StringField)
             'MsgBox " " & CInt(rsData!NumberField)
             rsData.MoveNext
        Wend
        
        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups