What is the faster way to insert/buck insert rows into SQL Server

dotnet framework

    Next

  • 1. A bug in Data Adapter Configuration Wizard (VB.Net for SQLS2k)
    == Description == VB.Net will unfaithfully represent primary keys when they are identified as an IDENTITY field for SQL Server tables. I will make these mistakes when producing Insert Stored Procedures and when producing DataSets. It will NOT make these mistakes when the field is 'ID', but it WILL create these mistakes when the field is named other than 'ID' for example 'CustID'. The mistakes in the Insert Stored procedure are: The id will not be recognized as an IDENTITY The id will be included as a parameter to be assigned a value by the user The id will be included in the insert into statement and the Values statement (as if a value will be assigned to it by the user) The id will be included in the select statement of the insert stored procedure The WHERE statement of the Insert stored procedure will have a parameter for the id equal to its parameter (CustID = @CustID) not (CustID = @@IDENTITY) The mistake in the DataSet is: The id field's AutoIncrement property is set to FALSE This mistake will be seen in the DataGrid: The ID will shown as NULL You will not be able to enter data into the table I can provide instruction on how to duplicate this error.
  • 2. Validate Data in SQL table
    I have a form that the user enters values on it. One of the fields I need to validate what is being entered against records in a SQL table. Something like doing a findfirst in Access and then doing a nomatch. How do I go about doing this? Thanks In Advance, Lou
  • 3. SQLServer or ADONET tricky
    I think there must be a trick (in SQLserver or ADONET) to do it: I have created a view with 4 fields. The last field is a calculated field myView (From a relationship between Table1(T1) and Table2(T2)) T1.Agent T1.Sales T2.Charge Total (Sales-Charge) Ken 2000 500 1500 Tom 3000 NULL NULL There is no value (Row) for Tom in the table who has the charge field (T2), as a consecuence the total is Null because the sustraction can be made. Is it possible to get this outputs for Tom without adding a record to the table who has the charge field(T2) ? Tom 3000 NULL 3000 What is important is to get a real value in the total field. any sug ken
  • 4. Hello? Is anyone reading these? I'm waiting for an answer, and I'
    "Dude" wrote: > There are quite a few unanswered posts in this NG. What do you say you get > busy answering these posts before we choose another development platform! > I'll keep watching... > > > "Tadow" wrote: I'm sorry Dude I'm newer to this data stuff then u probably are, but I would help u with info if I could. Anyhow I hope u get your problem solved and have a good day. I cant get the Microsoft xp sp2 updates to work because of Setup Errors.. Unable to read from or write to the database. So If u have any ideas pls help? L8r

What is the faster way to insert/buck insert rows into SQL Server

Postby Hao » Fri, 01 Jun 2007 23:04:49 GMT

I am developing a data center server in C#. We alaready have a legacy system 
that worked with great performance. The old system was unmanaged code in C++ 
and used ODBC driver SQLBindParameter to bind the data in the memory before 
dumping to the SQL Server. In the current C# version, I used the SqlBulkCopy 
to dump rows. However, I found that the performance still cannot compete 
with the old way of ODBC binding. The only operation I need is to append 
rows to tables.

I understand that MS recommens using the SqlClient, which is what I used 
(SqlBulkCopy). But I am still not happy about its performance (comparing to 
the old ODBC way).

Which driver/provider should I use to achieve the highest insert row(s) to 
SQL Server perfomance?
- SQL Server .Net
- OLE DB .Net
- ODBC.Net
- Others?

Thanks.
Hao




Re: What is the faster way to insert/buck insert rows into SQL Server

Postby William (Bill)Vaughn » Sat, 02 Jun 2007 00:23:52 GMT

I would echo this thread to the microsoft.public.sqlserver.programming 
group.
I would have said SqlClient would be the fastest--that or DBLib. ODBC, and 
OLE DB are OSFA interfaces that have more layers to cross before sending or 
receiving anything from SQL Server.

-- 
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
-----------------------------------------------------------------------------------------------------------------------








RE: What is the faster way to insert/buck insert rows into SQL Server

Postby v-wywang » Sat, 02 Jun 2007 14:48:29 GMT

Hello Hao.

I agree with William. SqlClient is the fastest way for SQL server database 
in ADO.net.

Bye the way, if you using ADO.net 2.0, I would like to suggest you specify 
SqlBulkCopy.BatchSize. This property is new in the .NET Framework version 
2.0 and indicates the Number of rows in each batch. The default value is 
zero, which means each WriteToServer operation is a single batch.

 http://www.**--****.com/ 
atchsize.aspx
[SqlBulkCopy.BatchSize Property ]

Hope this helps. Please let me know if you face any further issue on this. 
I'm glad to assist you.

Have a nice day,
Sincerely,
Wen Yuan
Microsoft Online Community Support 
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


Re: What is the faster way to insert/buck insert rows into SQL Server

Postby Cor Ligthert [MVP] » Sun, 03 Jun 2007 17:38:51 GMT

Hao,

Probably you will with your small program never reach the time with managed 
code as with unmanaged code. The same that you never can reach the 
performance, for small programs as you describe,  with C++ as you would have 
done it in Intel Assembler. However has a little bit more to do, than only 
to write to the SQLserver, you will see that you will most probably win it 
in the overall time. Let us not speak about maintainability because than you 
will win it with your C# in miles.

Just my thought,

Cor

"Hao" < XXXX@XXXXX.COM > schreef in bericht 





Re: What is the faster way to insert/buck insert rows into SQL Server

Postby Hao » Tue, 05 Jun 2007 22:12:06 GMT

Thanks for all the replies.
So far, my plan is to develop some buffer to utilize the BatchSize. There 
are challenges to having buffer implemented on the server side because of 
the amount of the data (hundreds of thousands of columns).

The product I am architecturing has a few large customers (data centers), 
such as eBay. The amount of data is huge. The old version of the software is 
working fine with archieving 3 to 4 GB data every day using ODBC and SQL 
binding, not to mention many other networking operations. The data block was 
constructed and bound before sending to the database. That is why the 
performance is fast.

In .Net bcp operation, I can buffer data to 5 rows, but I cannot buffer data 
for many more rows (like 30) because that will blow the memory (with the 
huge amount of columns in hundreds of tables). Fortunately, my testing shows 
that if I buffer 5 rows before BCP, I can probably achieve the task by 
requiring a high end server machine. I was hoping to see if there is any 
other "low level" or more "native" way in .Net to append data to SQL Server.

The perforamance of .Net really worries me a lot. We've spent a year in 
re-writing the server code in .Net but failed in overall performance. Now we 
are re-architecturing the entire system, and we are still not happy about 
the database perforamnce.

Does anyone know any serious networking or server application developed in 
.Net by Microsoft or other venders?

Thanks again.
Hao








Re: What is the faster way to insert/buck insert rows into SQL Server

Postby Charles Zhang » Wed, 06 Jun 2007 02:56:17 GMT

You might want to try out our SpeedyDB ADO.NET Provider.  It has two 
components, the server and the client. The server is using ODBC drives.


Charles Zhang
 http://www.**--****.com/ 
SpeedyDB ADO.NET Provider is the fastest ADO.NET provider over Wide Area 
Network (WAN).








Re: What is the faster way to insert/buck insert rows into SQL Server

Postby v-wywang » Thu, 07 Jun 2007 19:42:58 GMT

Hello Hao,
Thanks for your reply.

I'm sorry to hear BatchSize doesn't help on your scenario. As far as I 
know, SqlBulkCopy is the best component to copy large block data in ADO.net 
so far. There is truly some performance issue in managed code. In some 
field, it cannot reach the performance as with unmanaged code. 

I'm indeed sorry for any inconvenience this may have caused. 
Wen Yuan
Microsoft Online Community Support 
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


Re: What is the faster way to insert/buck insert rows into SQL Server

Postby William (Bill)Vaughn » Thu, 07 Jun 2007 22:57:11 GMT

Does anyone know any serious networking or server application developed in
.Net by Microsoft or other venders?"

You've got to be kidding. I suggest you look around. Many (many) of the
Fortune 1000 companies have implemented deadly serious large scale
applications using .NET.


--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
-----------------------------------------------------------------------------------------------------------------------

"Hao" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...



Re: What is the faster way to insert/buck insert rows into SQL Server

Postby Johnny Chin » Thu, 28 Jun 2007 11:28:56 GMT

Dim AsyncDataReader As IDataReader =
command.ExecuteReader(CommandBehavior.SequentialAccess)
Using transaction As SqlTransaction = Target.DBConn.BeginTransaction()

Using BulkCopy As SqlBulkCopy = New SqlBulkCopy(Target.DBConn,
SqlBulkCopyOptions.KeepIdentity Or SqlBulkCopyOptions.KeepNulls,
transaction)
  Dim dt As DataTable = New DataTable
  dt.Load(AsyncDataReader)

  BulkCopy.BatchSize = BatchSize
  BulkCopy.DestinationTableName = Tablename
  BulkCopy.BulkCopyTimeout = 0
  Try
   BulkCopy.WriteToServer(dt, DataRowState.Added)
  transaction.Commit()
   Catch ex As Exception
   MessageBox.Show(ex.Message)
   transaction.Rollback()
End Try

*** Sent via Developersdex  http://www.**--****.com/  ***

Similar Threads:

1.HOWTO: FormView Insert Operation - Get Row ID of Inserted Row

Using: MS SQL Server 2005 Sept 05 CTP, MS Visual Studio 2005 Beta 2

How can I get the SQL Server Row ID of the newly inserted row when adding a 
new record to the database using a FormView Control on a web page?

I've looked at the FormView_ItemInserted FormViewInsertedEventArgs but to no 
avail.

I need to immediately update a secondary table using this ID gotten from the 
newly created row.

-- 
Dan Sikorsky, MSCS BSCE BAB



2.fastest way to insert data (no bulk insert, no dts)

Hi all,

What is the fastest way to insert data using ADO.Net?

I have to insert more than 500.000 records and calling 
xCommand.ExecuteNonQuery is no good.

I also tried filling a data table first and then updating 
it.

SQL Server's Bulk insert operation is even more than good 
bu it reads from a text file only and also we plan to use 
both sqlsrv and oracle, so I can't use dts too.

I have to find a portable programmatic way.

thanx

3.tell VB when new row inserted in SQL server

I am running SQL server 2005 and want to be notified in VB when a new
row is inserted on a particular table.
Can I link to the table in visual express 2005 and have an event fired
when there is an insert on a particular table?

thanks

j

4.Returning guid from inserted row in SQL server 2005

Hi All

Can someone help get the rowGUID value after an insert

I am using VB.net 2005 and SQL server Express 2005

The column GUID is an uniqueidentifier column with default value 
(newsequentialid())

The following is my current function which is clumsy to say the least

I am sure there is a more elegant solution

Regards

Steve

----------------------------------------------------------------------------------------------------------
Public Function SaveParamDataGetGUID(ByVal mycmd As SqlCommand, ByVal 
mytable As String) As Guid

Dim con As New SqlConnection, guid As Guid, sql As String = ""

Dim myint As Int16 = 0

Try

con.ConnectionString = connectionstring

con.Open()

mycmd.Connection = con

mycmd.ExecuteNonQuery()

sql = "select max(mykey) as maxkey from " & mytable

mycmd.CommandText = sql

myint = mycmd.ExecuteScalar

sql = "select guid from " & mytable & " where mykey = " & myint

mycmd.CommandText = sql

guid = mycmd.ExecuteScalar

Return guid



Catch ex As SqlException

mymsgbox(ex.Message)

Return Nothing

Finally

If Not IsNothing(mycmd) Then

mycmd.Dispose()

mycmd = Nothing

End If

If Not IsNothing(con) Then

con.Close()

con.Dispose()

con = Nothing

End If

End Try

End Function

---------------------------------------------------------------------------------------------------------------------------------------------------


5.Multiple row insert only inserting one row?

I can't seem to find any place that a similar issue has been 
encountered, so here goes:

INSERT INTO destination(dest_id)
SELECT src_id
FROM source
WHERE NOT EXISTS (SELECT dest_id FROM destination WHERE dest_id = src_id)

The subquery executes as expected when run by itself, returning [n] 
rows. But when I try to execute the insert statement, only one row gets 
inserted. Or rather, it inserts one record, then runs the SELECT 
statement almost as if it was entirely separate:

(1 row(s) affected)
([n - 1] row(s) affected)

I should note that originally I was trying to insert several fields from 
the source table, but was experiencing the same behavior -- only one row 
getting inserted -- but some of the fields weren't getting inserted 
properly either. So I pared it down to trying to just get the ID's 
inserted, after which I planned on running an UPDATE.

Any advice on what I might be missing would be appreciated.

6. Insert values in one newly Inserted row in an existing EXCEL sheet

7. How to insert record into SQL 2k by Insert Statement

8. how to insert data from datagrid to datasource using insert sql statement



Return to dotnet framework

 

Who is online

Users browsing this forum: No registered users and 45 guest