Export SQL query results to text file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris McFarling

    Export SQL query results to text file

    What's the most efficient method to export the result set of a SQL query to
    a text file using ASP.NET? There could potentially be a few thousand rows.



  • George

    #2
    Re: Export SQL query results to text file

    To export anything will do...
    Just open a DataReader and start wrting into file..

    To import the best is to use bcp utility or BULK INSERT statement. Since
    this does not grow the Transaction Log.

    George.

    "Chris McFarling" <mcfly09@hotmai l.comwrote in message
    news:emNEe%23EG JHA.224@TK2MSFT NGP06.phx.gbl.. .
    What's the most efficient method to export the result set of a SQL query
    to a text file using ASP.NET? There could potentially be a few thousand
    rows.
    >
    >
    >

    Comment

    • Chris McFarling

      #3
      Re: Export SQL query results to text file

      So is row by row the only way to get data out of MSSQL (I'm running v2000
      btw) and into a text file? Is there an equivalent to SqlBulkCopy for getting
      data out of the database as opposed to into it?


      "George" <noemail@comcas t.netwrote in message
      news:ebwRRdGGJH A.2244@TK2MSFTN GP06.phx.gbl...
      To export anything will do...
      Just open a DataReader and start wrting into file..
      >
      To import the best is to use bcp utility or BULK INSERT statement. Since
      this does not grow the Transaction Log.
      >
      George.
      >
      "Chris McFarling" <mcfly09@hotmai l.comwrote in message
      news:emNEe%23EG JHA.224@TK2MSFT NGP06.phx.gbl.. .
      >What's the most efficient method to export the result set of a SQL query
      >to a text file using ASP.NET? There could potentially be a few thousand
      >rows.
      >>
      >>
      >>
      >

      Comment

      • George

        #4
        Re: Export SQL query results to text file

        Yes, row by row...
        There is no BulkExport only BulkImport. at least I am not aware of).

        The "Insert record" operation is pretty expensive. SQL server needs to do a
        lot of work.. Hence to optimize it there is an BulkImport operation.
        You might run 100000 single Insert operations for hours while BulkInsert
        will do it in a minutes.

        SELECT is not expensive at all. Hence no need for optimization.

        Although you might want to play with transaction level to to avoid
        unnecessary locking.
        You might want to set transaction level to "READ UNCOMMITTED".
        issue "SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED" right before SELECT
        statement.


        George.




        "Chris McFarling" <mcfly09@hotmai l.comwrote in message
        news:OIVan1GGJH A.4056@TK2MSFTN GP05.phx.gbl...
        So is row by row the only way to get data out of MSSQL (I'm running v2000
        btw) and into a text file? Is there an equivalent to SqlBulkCopy for
        getting data out of the database as opposed to into it?
        >
        >
        "George" <noemail@comcas t.netwrote in message
        news:ebwRRdGGJH A.2244@TK2MSFTN GP06.phx.gbl...
        >To export anything will do...
        >Just open a DataReader and start wrting into file..
        >>
        >To import the best is to use bcp utility or BULK INSERT statement. Since
        >this does not grow the Transaction Log.
        >>
        >George.
        >>
        >"Chris McFarling" <mcfly09@hotmai l.comwrote in message
        >news:emNEe%23E GJHA.224@TK2MSF TNGP06.phx.gbl. ..
        >>What's the most efficient method to export the result set of a SQL query
        >>to a text file using ASP.NET? There could potentially be a few thousand
        >>rows.
        >>>
        >>>
        >>>
        >>
        >
        >

        Comment

        Working...