Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4251960
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:43:53+00:00 2026-05-21T04:43:53+00:00

I have the following code that uses Sequence objects to read data from a

  • 0

I have the following code that uses Sequence objects to read data from a database table.
V1 works correctly but since the Seq.generate function is deprecated I receive compiler warnings.

I tried to rerplace this code with V2 (below) but it does not work correctly –
basically the reader is opened but only the first record is read – IOW – Read Next does not
work correctly.

To avoid compilation errors/warnings I need to convert V1 code to use a sequence expression.

Any ideas on the correct approach here.

(BTW – This code is based on examples in Rob Pickering’s Beginning F# book –
(Data Access/ADO.NET Section).

********************** V1 - Sequence Approach - Deprecated ************************

// execute a command using the Seq.generate
let execCommand (connName: string) (cmdString: string) = 
    Seq.generate       
        // This function gets called to open a connection and create a reader
        (fun () -> openReader connName cmdString)
        // This function gets called to read a single item in
        // the enumerable for a reader/connection pair
        (fun reader -> readRow(reader))
        (fun reader -> reader.Dispose())

*********************** V2  Alternative - (Does not work) ***************************

let generateSequence connName cmdString =
       seq { // This function gets called to open a connection and
              //create a reader
              use reader = openReader connName cmdString
              // This function gets called to read a single item in
               // the enumerable for a reader/connection pair
              yield readRow(reader) }

// execute a command using the Seq.generate
let execCommand (connName: string) (cmdString: string) = 

    generateSequence connName cmdString


*****************************  Common Functions  **********************************

// Open a db connection
let openReader connName cmdString =
    let conn = openSQLConnection(connName)
    let cmd = conn.CreateCommand(CommandText=cmdString,
                                 CommandType = CommandType.Text)
    let reader = cmd.ExecuteReader(CommandBehavior.CloseConnection)

// read a row from the data reader
let readRow (reader: #DbDataReader) =
    if reader.Read() then
        let dict = new Dictionary<string, obj>()
        for x in [ 0 .. (reader.FieldCount - 1) ] do
            dict.Add(reader.GetName(x), reader.[x])
        Some(dict)
    else
        None
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T04:43:54+00:00Added an answer on May 21, 2026 at 4:43 am

    You need to move around a few control structures to get this working.

    let generateSequence connName cmdString =
        seq { 
            use reader = openReader connName cmdString
            while reader.Read () do
                yield readRow reader
            yield None
        }
    
    let readRow (reader:#DbDataReader) =
        let dict = new Dictionary<string, obj>()
        for x in [0..(reader.FieldCount - 1)] do
            dict.Add (reader.GetName(x), reader.[x])
        Some dict
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following jQuery code that uses the scrollTo and localScroll plugins from
I have the following code that creates two objects (ProfileManager and EmployerManager) where the
I have the following code that uses 'paste' and AWK script inside Perl. use
I have the following code that uses the SqlClient.ExecuteScalar method to return an ID
I have the following code that uses a for loop and I would like
I have the following PHP code that uses cURL: $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,http://area51.stackexchange.com/users/flair/31.json); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
I have the following code that shows either a bug or a misunderstanding on
I have the following code that won't compile and although there is a way
I have the following code that sets a cookie: string locale = ((DropDownList)this.LoginUser.FindControl(locale)).SelectedValue; HttpCookie
I have the following code that I need to add an additonal object to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.