Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Unable to get random generation with OleDb
Message
From
18/09/2006 11:43:52
 
 
To
18/09/2006 11:16:22
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01154512
Message ID:
01154736
Views:
13
Hi,

>>Since the connection is open when the .Fill is called the dataadapter will leave the connection open and you will need to close it yourself afterwards
>
>Ok, this works. So, this means, if I have a robot that does those record selections every minute, I will have to issue the RAND(-1) everytime just before the SQL command in the same environment.

Essentially Yes - you will need to set up the environment when creating the connection. One option would be to make the query a SP and issue the RAND(-1) there. I usually open the connection in a method so I can consistently set the environment. Something like:
Private Shared Function OpenVFPConnection() As IDbConnection

        Dim VFPData = New System.Data.OleDb.OleDbConnection
        VFPData.ConnectionString = "whatever"

        Try
            VFPData.Open()
        Catch ex As Exception
            Throw New Exception("Failed to open Data Connectionn", ex)
        End Try

        'Set VFP environment bits:
        Dim oledbcmd As New OleDbCommand
        oledbcmd.Connection = VFPData
        oledbcmd.CommandText = "SET NULL OFF" + Chr(13) + Chr(10) + "SET DELETE ON" +CHR(13)+CHR(10)+"RAND(-1)"
        oledbcmd.CommandType = CommandType.Text
        oledbcmd.ExecuteNonQuery()
        Return CType(VFPData, IDbConnection)
    End Function
Then always use
.Command.Connection = OpenVFPConnection()
.etc
HTH,
Viv
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform