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. C / C++ / MFC
  4. Disconnected Recordset

Disconnected Recordset

Scheduled Pinned Locked Moved C / C++ / MFC
helpdatabasesysadmin
5 Posts 2 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.
  • Y Offline
    Y Offline
    yamini
    wrote on last edited by
    #1

    Hi All, I have a problem with disconnected recordsets.I ahve a component.One if it's function will get all the Records in a Database.I am passing the Recordset pointer from the server to the Client.I am using disconnected recordsets for this. I can see that at the server side I am getting the Recordset pointer.But, I could not get this pointer on the client side. the function has the protoype STDMETHODIMP GetAllElements([out]IUnknown **ppRecordset); I could get the Recordset pointer at the server side, but could not pass it to client.I am using Client side cursor(adUseClient) and standard Marshaling. what could be the problem . Thanx in advance for the help. Regards, yamini

    M 1 Reply Last reply
    0
    • Y yamini

      Hi All, I have a problem with disconnected recordsets.I ahve a component.One if it's function will get all the Records in a Database.I am passing the Recordset pointer from the server to the Client.I am using disconnected recordsets for this. I can see that at the server side I am getting the Recordset pointer.But, I could not get this pointer on the client side. the function has the protoype STDMETHODIMP GetAllElements([out]IUnknown **ppRecordset); I could get the Recordset pointer at the server side, but could not pass it to client.I am using Client side cursor(adUseClient) and standard Marshaling. what could be the problem . Thanx in advance for the help. Regards, yamini

      M Offline
      M Offline
      Mangesh Sardesai
      wrote on last edited by
      #2

      Hi, What DB are you using? I got similar problem with ACCESS Database, But an attempt with SQL Server database was successful. regards Mangesh Sardesai.

      Y 1 Reply Last reply
      0
      • M Mangesh Sardesai

        Hi, What DB are you using? I got similar problem with ACCESS Database, But an attempt with SQL Server database was successful. regards Mangesh Sardesai.

        Y Offline
        Y Offline
        yamini
        wrote on last edited by
        #3

        Hi, I am using MS Access DB for maintaining Records.I am using the SQL Query for getting records from Database. Please tell me how you did you fix the problem. Hope this will help. Thanx, Regards, yamini

        M 1 Reply Last reply
        0
        • Y yamini

          Hi, I am using MS Access DB for maintaining Records.I am using the SQL Query for getting records from Database. Please tell me how you did you fix the problem. Hope this will help. Thanx, Regards, yamini

          M Offline
          M Offline
          Mangesh Sardesai
          wrote on last edited by
          #4

          I am a VB developer and hence using the VB terminology. So please bear with me. The disconnected recordset did not worked with MS-ACCESS, the probable reason being,access being a file database, the file is closed as soon as the active connection of the recordset is set to nothing. This behaviour of the provider is be default and nothing can be done about it directly. (i.e. Set rs.ActiveConnection=Nothing wont work) The only thing you can do is - 1. Return a connected recordset to client process (rs1). 2. Create a new Recordset in client process (rs2) 3. Add exactly similar number & type of fields to rs2 as in returned Recordset(rs1). 4. open recordset (rs2). without any connection or source.This should be dynamic 5. run a loop inside which you will add the records from rs1 to rs2 one at a time. 6. close rs1. 7. use rs2 as you wish I have developed a small program in VB which you can refer & transpose to VC++. The database is an access database with a single table "table1" with fields - No Autonumber Name Text(50) =================================================== ActiveX dll =================================================== Option Explicit Dim conn As New ADODB.Connection '''''''''''''''''''''''''''''''' Private Sub Class_Initialize() conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\1.mdb;Persist Security Info=False;" End Sub Public Function GetRsData() As ADODB.Recordset Dim rs As New ADODB.Recordset rs.Open "table1", conn, adOpenStatic, adLockReadOnly, adCmdTable Set GetRsData = rs End Function ======================================================================== ======================================================================== The Client Executable ======================================================================== 'A simple form with a single button placed & code for button click event Private Sub Command1_Click() Dim cls As New Class1 Dim rs1 As New ADODB.Recordset Set rs1 = cls.GetRsData Dim rs2 As New ADODB.Recordset rs2.Fields.Append "No", adInteger rs2.Fields.Append "Name", adVarChar, 50 rs2.Open "", , adOpenDynamic, adLockOptimistic, adCmdUnknown Do Until rs1.EOF rs2.AddNew rs2("No").Value = rs1("No").Value rs2("Name").Value = rs1("Name").Value rs2.Update rs1.MoveNext Loop rs1.Close Set rs1 = Nothing rs2.MoveFirst Do Until rs2.EOF MsgBox rs2(0) &

          Y 1 Reply Last reply
          0
          • M Mangesh Sardesai

            I am a VB developer and hence using the VB terminology. So please bear with me. The disconnected recordset did not worked with MS-ACCESS, the probable reason being,access being a file database, the file is closed as soon as the active connection of the recordset is set to nothing. This behaviour of the provider is be default and nothing can be done about it directly. (i.e. Set rs.ActiveConnection=Nothing wont work) The only thing you can do is - 1. Return a connected recordset to client process (rs1). 2. Create a new Recordset in client process (rs2) 3. Add exactly similar number & type of fields to rs2 as in returned Recordset(rs1). 4. open recordset (rs2). without any connection or source.This should be dynamic 5. run a loop inside which you will add the records from rs1 to rs2 one at a time. 6. close rs1. 7. use rs2 as you wish I have developed a small program in VB which you can refer & transpose to VC++. The database is an access database with a single table "table1" with fields - No Autonumber Name Text(50) =================================================== ActiveX dll =================================================== Option Explicit Dim conn As New ADODB.Connection '''''''''''''''''''''''''''''''' Private Sub Class_Initialize() conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\1.mdb;Persist Security Info=False;" End Sub Public Function GetRsData() As ADODB.Recordset Dim rs As New ADODB.Recordset rs.Open "table1", conn, adOpenStatic, adLockReadOnly, adCmdTable Set GetRsData = rs End Function ======================================================================== ======================================================================== The Client Executable ======================================================================== 'A simple form with a single button placed & code for button click event Private Sub Command1_Click() Dim cls As New Class1 Dim rs1 As New ADODB.Recordset Set rs1 = cls.GetRsData Dim rs2 As New ADODB.Recordset rs2.Fields.Append "No", adInteger rs2.Fields.Append "Name", adVarChar, 50 rs2.Open "", , adOpenDynamic, adLockOptimistic, adCmdUnknown Do Until rs1.EOF rs2.AddNew rs2("No").Value = rs1("No").Value rs2("Name").Value = rs1("Name").Value rs2.Update rs1.MoveNext Loop rs1.Close Set rs1 = Nothing rs2.MoveFirst Do Until rs2.EOF MsgBox rs2(0) &

            Y Offline
            Y Offline
            yamini
            wrote on last edited by
            #5

            Hi, Thanx for the Reply.Actually ,I can't get that Recordset pointer at the client side.That is , it points to memory 0x00000000.So, I could not access the Database using that NULL pointer. My function at the server side goes this way . STDMETHODIMP GetAllElements([out]IUnknown **ppRecordset) { //Here I am getting the Recordset Pointer. } Upto this step I can get the Recordset pointer At the client side , void main() { IUnknown *pRecordset; //Instantiate the Component & get the Interface pointer say pInterface. pInterface->GetAllElement(&pRecordset);//pRecordset=0x00000000.Code Fails //Accessing Records goes here } How should I pass the pointer if I am wrong at the Client side. i am doing Standard Library Marshaling here.Is it to do something with this Marshaling ! Thanx in advance for the help. Regards, yamini

            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