Showing posts with label insert. Show all posts
Showing posts with label insert. Show all posts

Thursday, March 29, 2012

bulk sql insert task can do tables with identity?

i got some bulk insert tasks in SSIS inserting into some tables with identity set ON....

in 1 column. Can the bulk insert task go smoothly?

PS: i cannot find anywhere in the bulk insert task that can set the ignore identity columns...........

now my steps are prepare database -> create database -> bulk insert into tables

working on my previous problem, Jamie.

Open the Bulk Insert Task, select the Options page, select Options, open the drop down. Check "Enable Identity Insert".

Tuesday, March 27, 2012

Bulk Load Help - Parent Child relationship in schema

I am running a bulk load from a DTS package. I am able to insert the parent records succesfully into the article table, but I cannot get the child data to insert at all. The package returns an "executed succesfully" message, so I am having a tough time debugging. Here is my schema file, and a sample of the XML file I am trying to load. Please let me know if you spot anything in the schema I can fix (the xml file is supplied to me, and I have no control over it) All I am trying to insert in the child table (xmlTopic) is the Article_ID and the Topic_Type. Thanks in advance.

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
<xs:annotation>
<xs:appinfo>
<sql:relationship name="ArticleTopic"
parent="xmlARTICLE"
parent-key="ARTICLE_ID"
child="xmlTOPIC"
child-key="ARTICLE_ID" />
</xs:appinfo>
</xs:annotation>
<xs:element name="ARTICLE" sql:relation="xmlArticle" sql:key-fields="ARTICLE_ID">
<xs:complexType>
<xs:sequence>
<xs:element name="ATTRIBUTION" type="xs:string" sql:field="ATTRIBUTION"/>
<xs:element name="BLURB" type="xs:string" sql:field="BLURB"/>
<xs:element name="BODY" type="xs:string" sql:field="ARTICLE_BODY"/>
<xs:element name="BRAND" type="xs:string" sql:field="BRAND"/>
<xs:element name="BYLINE" type="xs:string" sql:field="BYLINE"/>
<xs:element name="COPYRIGHT" type="xs:string" sql:field="COPYRIGHT"/>
<xs:element name="FEATURE_BLURB" type="xs:string" sql:field="FEATURE_BLURB"/>
<xs:element name="FEATURE_IMAGE" type="xs:string" sql:field="FEATURE_IMAGE"/>
<xs:element name="HEADLINE" type="xs:string" sql:field="HEADLINE"/>
<xs:element name="NEWS_TYPE" type="xs:string" sql:field="NEWS_TYPE"/>
<xs:element name="SOURCE" type="xs:string" sql:field="SOURCE"/>
<xs:element name="TEASER" type="xs:string" sql:field="TEASER"/>
<xs:element name="URL" type="xs:string" sql:field="URL"/>
<xs:element name="TOPICS" sql:mapped="false">
<xs:complexType>
<xs:sequence>
<xs:element name="TOPIC" sql:relation="xmlTopic" sql:relationship="ArticleTopic" sql:key-fields="xmlTopicID">
<xs:complexType>
<xs:attribute name="TOPIC_TYPE" type="xs:string" sql:field="TOPIC_TYPE"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="ARTICLE_ID" type="xs:string" sql:field="ARTICLE_ID"/>
<xs:attribute name="POSTING_DATE" type="xs:string" sql:field="POSTING_DATE"/>
<xs:attribute name="ARCHIVE_DATE" type="xs:string" sql:field="ARCHIVE_DATE"/>
</xs:complexType>
</xs:element>
</xs:schema>

<?xml version="1.0"?>
<!DOCTYPE NEWSFEED SYSTEM "http://www.blah.com">
<NEWSFEED>
<ARTICLE ARTICLE_ID="531320" POSTING_DATE="08-Mar-2006" ARCHIVE_DATE="01-Mar-2007">
<NEWS_TYPE>blah</NEWS_TYPE>
<HEADLINE><![CDATA[blah]]></HEADLINE>
<BLURB><![CDATA[blah]]></BLURB>
<BYLINE><![CDATA[blah]]></BYLINE>
<BODY><![CDATA[blahblahblah]]></BODY>
<ATTRIBUTION><![CDATA[blah]]></ATTRIBUTION>
<SOURCE><![CDATA[blah]]></SOURCE>
<FEATURE_BLURB><![CDATA[blah]]></FEATURE_BLURB>
<FEATURE_IMAGE></FEATURE_IMAGE>
<TEASER><![CDATA[blah]]></TEASER>
<COPYRIGHT><![CDATA[blah]]></COPYRIGHT>
<BRAND><![CDATA[vlah]]></BRAND>
<URL><![CDATA[blah]></URL>
<TOPICS>
<TOPIC TOPIC_TYPE="BLPR"/>
<TOPIC TOPIC_TYPE="BLPR2"/>
</TOPICS>
</ARTICLE>
</NEWSFEED>

Well it turns out I answered my own question. I checked the MSDN Library(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sqlxml3/htm/bulkload_7pv0.asp - see sql:relationship and the Key Ordering Rule), and found the following info:

"This means that in defining the <Customer> element, you must specify the CustomerID attribute in the schema before you specify <sql:relationship>. Otherwise, when an <Order> element enters into scope, XML Bulk Load generates a record for the CustOrder table; and when the XML Bulk Load reaches the </Order> end tag, it sends the record to SQL Server without the CustomerID foreign key column value."

So I put my sql:relationship at the end of the schema file, and it worked like a charm. As reference, here is my revised schema file:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sql="urn:schemas-microsoft-com:mapping-schema">

<xsd:element name="ARTICLE" sql:relation="xmlArticle">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="ATTRIBUTION" type="xsd:string" sql:field="ATTRIBUTION"/>
<xsd:element name="BLURB" type="xsd:string" sql:field="BLURB"/>
<xsd:element name="BODY" type="xsd:string" sql:field="ARTICLE_BODY"/>
<xsd:element name="BRAND" type="xsd:string" sql:field="BRAND"/>
<xsd:element name="BYLINE" type="xsd:string" sql:field="BYLINE"/>
<xsd:element name="COPYRIGHT" type="xsd:string" sql:field="COPYRIGHT"/>
<xsd:element name="FEATURE_BLURB" type="xsd:string" sql:field="FEATURE_BLURB"/>
<xsd:element name="FEATURE_IMAGE" type="xsd:string" sql:field="FEATURE_IMAGE"/>
<xsd:element name="HEADLINE" type="xsd:string" sql:field="HEADLINE"/>
<xsd:element name="NEWS_TYPE" type="xsd:string" sql:field="NEWS_TYPE"/>
<xsd:element name="SOURCE" type="xsd:string" sql:field="SOURCE"/>
<xsd:element name="TEASER" type="xsd:string" sql:field="TEASER"/>
<xsd:element name="URL" type="xsd:string" sql:field="URL"/>
<xsd:element name="TOPIC" sql:relation="xmlTopic" sql:relationship="ArticleTopic">
<xsd:complexType>
<xsd:attribute name="TYPE2" type="xsd:string" sql:field="TopicType"/>
<xsd:attribute name="TOPIC_TYPE" type="xsd:string" sql:field="TopicID"/>
<xsd:attribute name="SIGNIFICANCE_FACTOR" type="xsd:string" sql:field="SignificanceFactor"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="ARTICLE_ID" type="xsd:string" sql:field="ARTICLE_ID"/>
<xsd:attribute name="POSTING_DATE" type="xsd:string" sql:field="POSTING_DATE"/>
<xsd:attribute name="ARCHIVE_DATE" type="xsd:string" sql:field="ARCHIVE_DATE"/>
</xsd:complexType>
</xsd:element>

<xsd:annotation>
<xsd:appinfo>
<sql:relationship name="ArticleTopic"
parent="xmlArticle"
parent-key="ARTICLE_ID"
child="xmlTopic"
child-key="ARTICLE_ID" />
</xsd:appinfo>
</xsd:annotation>

</xsd:schema>

sql

BULK LOAD - worked, but with this error msg - meaning?

Hi,
My bulk load worked, however, I had some messages returned. Just
wondering what they mean? Thanks
This is my Bulk Insert stmt:
BULK INSERT dbo.[Table_Load] FROM 'c:\admin\myFile.txt' WITH
(FIELDTERMINATOR='\t',ROWTERMINATOR='\n',CODEPAGE = 'OEM',FIRSTROW=2)
These are the messages returned:
Bulk load: DataFileType was incorrectly specified as char. DataFileType
will be assumed to be widechar because the data file has a Unicode
signature.
Bulk load: DataFileType was incorrectly specified as char. DataFileType
will be assumed to be widechar because the data file has a Unicode
signature.
(459 row(s) affected)
Hi
If you don't specify a DATAFILETYPE then 'char' is assumed and it looks like
you have a unicode file, therefore you should specify 'widechar'. Lookup BULK
INSERT in Books Online for more information.
John
"tootsuite@.gmail.com" wrote:

> Hi,
> My bulk load worked, however, I had some messages returned. Just
> wondering what they mean? Thanks
> This is my Bulk Insert stmt:
> BULK INSERT dbo.[Table_Load] FROM 'c:\admin\myFile.txt' WITH
> (FIELDTERMINATOR='\t',ROWTERMINATOR='\n',CODEPAGE = 'OEM',FIRSTROW=2)
> These are the messages returned:
> Bulk load: DataFileType was incorrectly specified as char. DataFileType
> will be assumed to be widechar because the data file has a Unicode
> signature.
> Bulk load: DataFileType was incorrectly specified as char. DataFileType
> will be assumed to be widechar because the data file has a Unicode
> signature.
> (459 row(s) affected)
>

BULK LOAD - worked, but with this error msg - meaning?

Hi,
My bulk load worked, however, I had some messages returned. Just
wondering what they mean' Thanks
This is my Bulk Insert stmt:
BULK INSERT dbo.[Table_Load] FROM 'c:\admin\myFile.txt' WITH
(FIELDTERMINATOR='\t',ROWTERMINATOR='\n'
,CODEPAGE = 'OEM',FIRSTROW=2)
These are the messages returned:
Bulk load: DataFileType was incorrectly specified as char. DataFileType
will be assumed to be widechar because the data file has a Unicode
signature.
Bulk load: DataFileType was incorrectly specified as char. DataFileType
will be assumed to be widechar because the data file has a Unicode
signature.
(459 row(s) affected)Hi
If you don't specify a DATAFILETYPE then 'char' is assumed and it looks like
you have a unicode file, therefore you should specify 'widechar'. Lookup BUL
K
INSERT in Books Online for more information.
John
"tootsuite@.gmail.com" wrote:

> Hi,
> My bulk load worked, however, I had some messages returned. Just
> wondering what they mean' Thanks
> This is my Bulk Insert stmt:
> BULK INSERT dbo.[Table_Load] FROM 'c:\admin\myFile.txt' WITH
> (FIELDTERMINATOR='\t',ROWTERMINATOR='\n'
,CODEPAGE = 'OEM',FIRSTROW=2)
> These are the messages returned:
> Bulk load: DataFileType was incorrectly specified as char. DataFileType
> will be assumed to be widechar because the data file has a Unicode
> signature.
> Bulk load: DataFileType was incorrectly specified as char. DataFileType
> will be assumed to be widechar because the data file has a Unicode
> signature.
> (459 row(s) affected)
>

BULK LOAD - worked, but with this error msg - meaning?

Hi,
My bulk load worked, however, I had some messages returned. Just
wondering what they mean' Thanks
This is my Bulk Insert stmt:
BULK INSERT dbo.[Table_Load] FROM 'c:\admin\myFile.txt' WITH
(FIELDTERMINATOR='\t',ROWTERMINATOR='\n',CODEPAGE = 'OEM',FIRSTROW=2)
These are the messages returned:
Bulk load: DataFileType was incorrectly specified as char. DataFileType
will be assumed to be widechar because the data file has a Unicode
signature.
Bulk load: DataFileType was incorrectly specified as char. DataFileType
will be assumed to be widechar because the data file has a Unicode
signature.
(459 row(s) affected)Hi
If you don't specify a DATAFILETYPE then 'char' is assumed and it looks like
you have a unicode file, therefore you should specify 'widechar'. Lookup BULK
INSERT in Books Online for more information.
John
"tootsuite@.gmail.com" wrote:
> Hi,
> My bulk load worked, however, I had some messages returned. Just
> wondering what they mean' Thanks
> This is my Bulk Insert stmt:
> BULK INSERT dbo.[Table_Load] FROM 'c:\admin\myFile.txt' WITH
> (FIELDTERMINATOR='\t',ROWTERMINATOR='\n',CODEPAGE = 'OEM',FIRSTROW=2)
> These are the messages returned:
> Bulk load: DataFileType was incorrectly specified as char. DataFileType
> will be assumed to be widechar because the data file has a Unicode
> signature.
> Bulk load: DataFileType was incorrectly specified as char. DataFileType
> will be assumed to be widechar because the data file has a Unicode
> signature.
> (459 row(s) affected)
>

bulk insertion

hi

hi i have common problem.

which is the best way to insert 1000 rows at a time in sql server 2000.

From where you want to insert?

You can use the following approaches

apporach 1:

Use bcp to backup the data on text file (delimited file) - from soruce server

http://msdn2.microsoft.com/en-us/library/ms162802.aspx

Use BULK INSERT to reload the data on the target server

http://msdn2.microsoft.com/en-us/library/ms188365.aspx

approach 2:

Use DTS to load the data from one server to another server

http://msdn2.microsoft.com/en-us/library/aa902640(SQL.80).aspx

approach 3:

Use linked server to get the source data on the target server

http://msdn2.microsoft.com/en-us/library/aa213778(SQL.80).aspx

|||

If the data is in a delimited text file, use bcp; it's quick and flexible.

Read up on [bcp] in Books Online.

bulk inserting uniqueidentifier column

Hi at all,
I'm trying to bulk insert a uniqueidentifier column from unicode file.
In my file I have guid generated from c# application and they are
formatted in this way (separated by "|") :

guid | field1 | field2
fc0c0c42-438e-4897-96db-8b0489e873ef|field1|field2

In my destination table I have three column:
id (uniqueidentifier)
field1 (nvarchar)
field2 (nvarchar)

I use in bulk insert a format file like this :

9.0
3
1SQLNCHAR00"|\0"1IDLatin1_General_CI_AS
2SQLNCHAR00"|\0"2Field1Latin1_General_CI_AS
3SQLNCHAR00"|\0"3Field2Latin1_General_CI_AS

and I use this script

BULK INSERT [dbo].[KWTA2] FROM 'd:\WTA2.txt'
WITH (FORMATFILE = 'd:\wta2Format.FMT')

It doesn't work, it prints out
Msg 8152, Level 16, State 13, Line 2
String or binary data would be truncated.

I've also tried to specify in FMT file SQLUNIQUEID instead of SQLNCHAR
and it works perfectly but it imports another data. For example the
guid fc0c0c42-438e-4897-96db-8b0489e873ef became
00350031-0039-0033-3100-300030003000

Please can you help me?
Why sql converts alphanumerical GUID into only numbers ID?
How can I bulk insert GUID? (I didn't find anything googling around :
\ )

Thanks!

Bob(bob.speaking@.gmail.com) writes:

Quote:

Originally Posted by

I'm trying to bulk insert a uniqueidentifier column from unicode file.
In my file I have guid generated from c# application and they are
formatted in this way (separated by "|") :
>
guid | field1 | field2
fc0c0c42-438e-4897-96db-8b0489e873ef|field1|field2
>
In my destination table I have three column:
id (uniqueidentifier)
field1 (nvarchar)
field2 (nvarchar)
>
I use in bulk insert a format file like this :
>
9.0
3
1 SQLNCHAR 0 0 "|\0" 1 ID Latin1_General_CI_AS
2 SQLNCHAR 0 0 "|\0" 2 Field1


Latin1_General_CI_AS

Quote:

Originally Posted by

3 SQLNCHAR 0 0 "|\0" 3 Field2


Latin1_General_CI_AS

Does the file really consist of one single line?

Assuming that you have one record per line in the file, the terminator
for field 3 should be \r\0\n\0. What happens now is that Field2 in the
first record extends into the GUID in the second record, and then it
goes downhill from there.

Quote:

Originally Posted by

I've also tried to specify in FMT file SQLUNIQUEID instead of SQLNCHAR
and it works perfectly but it imports another data. For example the
guid fc0c0c42-438e-4897-96db-8b0489e873ef became
00350031-0039-0033-3100-300030003000


SQLUNIQUEID is what you would use in a binary file. It's not applicable
here.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||>

Quote:

Originally Posted by

Does the file really consist of one single line?
>
Assuming that you have one record per line in the file, the terminator
for field 3 should be \r\0\n\0. What happens now is that Field2 in the
first record extends into the GUID in the second record, and then it
goes downhill from there.


I'm sorry, cut and pasting sample text file I've removed the correct
syntax :\
In fact the last line has the terminator you specified. :)

Quote:

Originally Posted by

Quote:

Originally Posted by

I've also tried to specify in FMT file SQLUNIQUEID instead of SQLNCHAR
and it works perfectly but it imports another data. For example the
guid fc0c0c42-438e-4897-96db-8b0489e873ef became
00350031-0039-0033-3100-300030003000


>
SQLUNIQUEID is what you would use in a binary file. It's not applicable
here.


I'm migrating this bulk insert frm sql server 2000... in 2005 this
doesn't work. Is it caused by more strictly rules in 2005 engine?
Is sql converting my "char" guid in binary?

Thanks for the prompt reply :)

bobsql

BULK INSERTing UNICODE data with format files

Hi,
I am trying to bulk insert data with UNICODE characters into a table using a
format file. I am using SQL Server 2000 with all the latest SPs.
When I try to bulk insert the data I get the following error.
"Bulk Insert: Unexpected end-of-file (EOF) encountered in data file."
What am I doing incorrectly?
Please help me out with this. What is the correct way to do this. My data
file will have UNICODE characters (for nchar, nvarchar sql types) and
would also have data for other types like (int, datetime etc). And I want to
use a format file.
Thanks in anticipation,
Nitin M
I have created the data file in the following way.
---
StreamWriter DataWriter = new
StreamWriter("data.txt",false,System.Text.Encoding.Unicode);
DataWriter.WriteLine("1/1/2005@.@.aa@.@.aaaa@.@.23@.@.-1.9879@.@.");
DataWriter.Close();
----
--
This is the definition of my table.
---
CREATE TABLE [dbo].[AllTypes] (
[mydate] [datetime] NULL ,
[mychar] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[myvarchar] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[myint] [int] NULL ,
[myreal] [real] NULL
) ON [PRIMARY]
---
The bulk insert query that I use
---
bulk insert alltypes from 'data.txt' with
(
datafiletype='widechar',
formatfile = 'bcp.format.txt',
tablock
)
---
My format file
---
8.0
5
1 SQLNCHAR 0 0 "@.@." 1 mydate ""
2 SQLNCHAR 0 0 "@.@." 2 mychar SQL_Latin1_General_CP1_CI_AS
3 SQLNCHAR 0 0 "@.@." 3 myvarchar SQL_Latin1_General_CP1_CI_AS
4 SQLNCHAR 0 0 "@.@." 4 myint ""
5 SQLNCHAR 0 0 "@.@.\r\n" 5 myreal ""
---Nitin M (nitin@.nowhere.com) writes:

> I am trying to bulk insert data with UNICODE characters into a table
> using a format file. I am using SQL Server 2000 with all the latest
> SPs.
> When I try to bulk insert the data I get the following error.
> "Bulk Insert: Unexpected end-of-file (EOF) encountered in data file."
> What am I doing incorrectly?
> Please help me out with this. What is the correct way to do this. My
> data file will have UNICODE characters (for nchar, nvarchar sql types)
> and would also have data for other types like (int, datetime etc). And I
> want to use a format file.
I only got half-way of solving this puzzle. You need to specify the
separators as Unicode as well. I tried this:
8.0
5
1 SQLNCHAR 0 0 "\0@.\0@." 1 mydate ""
2 SQLNCHAR 0 0 "\0@.\0@." 2 mychar SQL_Latin1_General_CP1_CI_AS
3 SQLNCHAR 0 0 "\0@.\0@." 3 myvarchar SQL_Latin1_General_CP1_CI_AS
4 SQLNCHAR 0 0 "\0@.\0@." 4 myint ""
5 SQLNCHAR 0 0 "\0@.\0@.\0\r\0\n" 5 myreal ""
This got me past the EOF error, but instead I got conversion errors for
the numeric values. You could make all columns characters columns, so
you see what BCP actually finds, and then maybe modify the separators
from this.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Hi Erland,
Thanks a lot for looking into this.
Even I got around the problem by specifying separators as Unicode. The
reason you are getting conversion errors is due to the byte ordering of the
separators. Try the other byte order. It works for me. I am not getting any
conversion errors.
Is there no other cleaner way around this?
Thanks,
Nitin
"Erland Sommarskog" <esquel@.sommarskog.se> wrote in message
news:Xns973F74A723AEFYazorman@.127.0.0.1...
> Nitin M (nitin@.nowhere.com) writes:
>
> I only got half-way of solving this puzzle. You need to specify the
> separators as Unicode as well. I tried this:
> 8.0
> 5
> 1 SQLNCHAR 0 0 "\0@.\0@." 1 mydate ""
> 2 SQLNCHAR 0 0 "\0@.\0@." 2 mychar SQL_Latin1_General_CP1_CI_AS
> 3 SQLNCHAR 0 0 "\0@.\0@." 3 myvarchar SQL_Latin1_General_CP1_CI_AS
> 4 SQLNCHAR 0 0 "\0@.\0@." 4 myint ""
> 5 SQLNCHAR 0 0 "\0@.\0@.\0\r\0\n" 5 myreal ""
> This got me past the EOF error, but instead I got conversion errors for
> the numeric values. You could make all columns characters columns, so
> you see what BCP actually finds, and then maybe modify the separators
> from this.
>
> --
> Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
> Books Online for SQL Server 2005 at
> http://www.microsoft.com/technet/pr...oads/books.mspx
> Books Online for SQL Server 2000 at
> http://www.microsoft.com/sql/prodin...ions/books.mspx|||Nitin M (nitin@.nowhere.com) writes:
> Thanks a lot for looking into this.
> Even I got around the problem by specifying separators as Unicode. The
> reason you are getting conversion errors is due to the byte ordering of
> the separators. Try the other byte order. It works for me. I am not
> getting any conversion errors.
Ah! Glad to hear that you where able to find it out yourself.

> Is there no other cleaner way around this?
The obvious idea would be to save the format file as Unicode, but that
does not work; you only get a message about unknown version. I tried in
SQL 2005 as well, but SQL 2005 appears to think that a Unicode file must
be an XML format file.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

Sunday, March 25, 2012

Bulk Insert: Unexpected end-of-file (EOF) encountered...

Hi to all,
I have a problem about a importation of a file *.csv with SQL Server,
through a bulk insert, called in a store procedure that a c# sw calls.
This is the description of the error:
--
System.Data.SqlClient.SqlException stata individuata
Message="Bulk Insert: Unexpected end-of-file (EOF) encountered in
data file.\r\nOLE DB provider 'STREAM' reported an error. The provider
did not give any information about the error.\r\nOLE DB error trace
[OLE/DB Provider 'STREAM' IRowset::GetNextRows returned 0x80004005:
The provider did not give any information about the error.].\r\nThe
statement has been terminated."
Source=".Net SqlClient Data Provider"
ErrorCode=-2146232060
Class=16
LineNumber=1
Number=4832
Procedure=""
Server="ets3971"
State=1
StackTrace:
at System.Data.SqlClient.SqlConnection.OnError(SqlExc eption
exception, Boolean breakConnection)
at
System.Data.SqlClient.SqlInternalConnection.OnErro r(SqlException
exception, Boolean breakConnection)
at
System.Data.SqlClient.TdsParser.ThrowExceptionAndW arning(TdsParserStateObject
stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,
SqlCommand cmdHandler, SqlDataReader dataStream,
BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject
stateObj)
at
System.Data.SqlClient.SqlCommand.FinishExecuteRead er(SqlDataReader ds,
RunBehavior runBehavior, String resetOptionsString)
at
System.Data.SqlClient.SqlCommand.RunExecuteReaderT ds(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean
async)
at
System.Data.SqlClient.SqlCommand.RunExecuteReader( CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String
method, DbAsyncResult result)
at
System.Data.SqlClient.SqlCommand.InternalExecuteNo nQuery(DbAsyncResult
result, String methodName, Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at sarbox.Default.LoadFlux_Click(Object sender, EventArgs e) in
c:\Inetpub\wwwroot\Zarbox2.2\SoxAdmin\Default.aspx .cs:line 1509
--

Th@.nks to all

AB@.AB@. (b.aharon44@.gmail.com) writes:

Quote:

Originally Posted by

I have a problem about a importation of a file *.csv with SQL Server,
through a bulk insert, called in a store procedure that a c# sw calls.
This is the description of the error:
--
System.Data.SqlClient.SqlException stata individuata
Message="Bulk Insert: Unexpected end-of-file (EOF) encountered in
data file.\r\nOLE DB provider 'STREAM' reported an error. The provider
did not give any information about the error.\r\nOLE DB error trace
[OLE/DB Provider 'STREAM' IRowset::GetNextRows returned 0x80004005:
The provider did not give any information about the error.].\r\nThe
statement has been terminated."


Unfortunately, the information you posted is not sufficient to help
you. Could you please post:

1) The BULK INSERT statement.
2) Any format file you are using.
3) A short sample of the data file.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||On 17 Apr, 23:40, Erland Sommarskog <esq...@.sommarskog.sewrote:

Quote:

Originally Posted by

AB@. (b.aharo...@.gmail.com) writes:

Quote:

Originally Posted by

I have a problem about a importation of a file *.csv with SQL Server,
through a bulk insert, called in a store procedure that a c# sw calls.
This is the description of the error:
--
System.Data.SqlClient.SqlException stata individuata
Message="Bulk Insert: Unexpected end-of-file (EOF) encountered in
data file.\r\nOLE DB provider 'STREAM' reported an error. The provider
did not give any information about the error.\r\nOLE DB error trace
[OLE/DB Provider 'STREAM' IRowset::GetNextRows returned 0x80004005:
The provider did not give any information about the error.].\r\nThe
statement has been terminated."


>
Unfortunately, the information you posted is not sufficient to help
you. Could you please post:
>
1) The BULK INSERT statement.
2) Any format file you are using.
3) A short sample of the data file.
>
--
Erland Sommarskog, SQL Server MVP, esq...@.sommarskog.se
>
Books Online for SQL Server 2005 athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books...
Books Online for SQL Server 2000 athttp://www.microsoft.com/sql/prodinfo/previousversions/books.mspx


I have risolve it - thanks|||This looks resolved, but I've experienced this problem before.
Resolution occured in one of three ways:

1) We sometimes get files that are cut off prematurely and a line
will only be a fraction completed. This will fail a bulk-insert.
2) Sometimes an extra carriage return is at the end of the file.
I've seen this fail the bulk-insert with an Unexecpected EOF message.
3) Sometimes I just couldn't figure out the answer and using DTS
instead of bulk insert resolved the problem.

I hope that helps somebody. :D

-Utah

Bulk Insert: One Row not importing in...

Ok so I got this working:

BULK INSERT

dbo.tbCheckPointTest

FROM 'c:\inetpub\wwwroot\upload\maxie_task_aging.csv'

WITH

(DATAFILETYPE = 'char', FIELDTERMINATOR = ',',

FIRSTROW = 2, ROWS_PER_BATCH = 6, ROWTERMINATOR = '\n')

My data file looks like this:

REPORT_EXECUTED_ON:20070403_170001 Research 306 263 2470 State 1031 7 0 Program 13 1 0 Program Tech 85 69 139

Total of 6 rows, so I indicate to start on Row 2, yet only the last three lines are getting into my table.

I have changed and manipulated the query varies counts, but still just the last three lines get imported.

Thoughts?

Thanks!

Hi,

From the looks of your data file, it is difficult to tell how many blank lines are associated with your data file.

It appears that "Research" may begin on line 4, in which case you would have only three rows of data: "Research", "State", and "Program".

I am confused by the fact that you get the last three rows: "State", "Program", and "Program Tech".

Is it possible that some rows are terminated by "0A0D" and others only by "0A" or "0D", and "\n" is being interpreted as strictly "0A0D" (hexadecimal)?

I also am confused by your use of "FIELDTERMINATOR = ',' ", since I don't see any commas in the data you have displayed.

Dan

|||

Sorry. I had the .csv open with excel when I copied and pasted it:

REPORT_EXECUTED_ON:20070404_110001

Research Specialist - Research , 340, 91, 2635
State Worker (Interim) , 918, 3, 0
Program Specialist - Quality Assurance Specialist , 16, 1, 0
Program Technician - Data Entry Hold , 82, 28, 160

I am going to see if anything you suggested will help.

|||

The problem seems to be that the BULK INSERT function seems to expect all the rows in the file to have the correct number of fields for the target table (even those being skipped). So it is ignoring the newlines until it has found enough commas (and then counts any other commas until it finds the row terminator as part of that field).

Try loading the file:

REPORT_EXECUTED_ON:20070404_110001,,,
,,,
Research Specialist - Research , 340, 91, 2635
State Worker (Interim) , 918, 3, 0
Program Specialist - Quality Assurance Specialist , 16, 1, 0
Program Technician - Data Entry Hold , 82, 28, 160


Though you will need a FIRSTROW = 3

If you put the last field into a varchar rather than an int then if you add commas to the end (e.g. 2635,,,,) then you will find that these commas end up in that field (if not then it will complain about unexpected characters when it tries to convert it to an int or whatever).

So any rows to be skipped should have the correct number of field separators in them (3) or they will not be included in the skip count.

|||

Thank you, that solved the issue. Now I have to get w/the programmer who delivers the file to me.

Smile

|||

Nice catch, Dhericean!

Dan

BULK INSERT: marked for deprecation?

I read in Microsoft SQL Server 2005 Integration Services by Kirk Haselden that the BULK INSERT task was provided for backward compatibility and its use is disrecommended.

But after looking on the web I cannot find information supporting this.

Do you think the BULK INSERT task should be used for new development?

Thanks

It's not currently marked for deprecation. It may be in the future, because using the data flow and SQL Server Destinations or using the "fast load" option on the OLE DB destinations will be much more flexible.

I would avoid using the Bulk Insert Task simply because of its rigid restrictions and the fact that it requires a CSV formatted file. That's way too limiting for me.|||

I agree with you, the Data flow task is much more flexible. And it performed better than the BULK INSERT in my case...
But the big advantage of the BULK INSERT (and some see it as a disadvantage) is that it uses Format Files.

In our case, we have flat files from about 20 providers. There's is no way of suppling the Data flow task with a transformation schema, so that would mean creating/maintaining 20 different Data flow tasks (each in a different package).

Another implementation would be to use a generic SSIS with a Bulk Insert Task taking as parameters the source/destination and a format file. In that case, we would have to create/maintain 20 different format files.

So I'm currently weighting each option. The restrictions of the BULK INSERT such as the flat file requirement are not a problem in this case. Performance is at a certain extent. Usability, deployment and maintenance are the most important criteria.

Thanks!

|||You might want to provide feedback over on connect.microsoft.com and share your feelings.

Perhaps Matt Masson, Michael Entin, or others from MS can jump in and share their opinions or even MS' official stance.|||

Phil Brammer wrote:

You might want to provide feedback over on connect.microsoft.com and share your feelings.

Perhaps Matt Masson, Michael Entin, or others from MS can jump in and share their opinions or even MS' official stance.

Are you suggesting I ask them about the BULK INSERT being deprecated or about adding format file option to the Data flow task? I'm not sure...

What I would want is a place to seek advice on implementation. There's always many ways to do the same thing, especially when using T-SQL and SSIS. But do I post in the T-SQL forum or in the SSIS forum?

|||

fleo wrote:

Are you suggesting I ask them about the BULK INSERT being deprecated or about adding format file option to the Data flow task? I'm not sure...

What I would want is a place to seek advice on implementation. There's always many ways to do the same thing, especially when using T-SQL and SSIS. But do I post in the T-SQL forum or in the SSIS forum?

I'm suggesting that you post your feedback (via https://connect.microsoft.com/SQLServer/feedback)on how you want the BULK INSERT task to stick around and not be deprecated.

As far as which forum, well, that just depends on the scenario. Don't be too worried about which forum to post in as if we feel it needs to be moved, there are a few of us here that can do that accordingly.|||

There may have been deprecation discussions when Kirk was originally writing his book, but as of now, there are no plans to deprecate the Bulk Insert task.

As previously mentioned, you get more flexibility using the data flow approach, and if you’re able to use the “fast load” option, you might even get a 10-15% performance increase over the BULK INSERT tasks. You can weigh out both options, but as Phil has suggested, using a data flow is generally the recommended approach.

|||

I think the inflexibility is a decision point between using the Data Flow over the Bulk Insert Task and whilst I would normally use Data Flow perhaps more out of habit, I think fleo's point about being able to load files of any format, by dynamically setting properties is very valid.

It is something that cannot be achieved with the Data Flow task, and should not be underestimated. It can be a very powerful tool, and one reason why many people use the T-SQL equivalent or even BCP still. I just like being able to get that functionality within the SSIS framework so I can use configurations and logging and all that good stuff.

Use it and save time, and of course Matt has responded in the positive too!

|||

hI Matt,

so the Flat File Source has better performance than the BULK INSERT Task...

Where can I found this kind of information?

Also about the deprecation topic, why hasn't it written in the MSDN documentation?

Thank you

|||

Hi Antonio,

Unfortunately, the 10-15% performance increase that I quoted wasn't from any official testing or documentation... I believe it came from a developer from an internal group that was testing out both methods. There's typically a lot of variables involved in these tests, so I'd recommend trying out both approaches yourself and seeing which works best in your situation.

I'm not sure what you're asking about the deprecation topic. I wasn't able to find any official reference to the task being deprecated when I first looked into this, and MSDN typically doesn't explicitly mention that a task is NOT going to be deprecated.

Thanks,

~Matt

BULK INSERT: marked for deprecation?

I read in Microsoft SQL Server 2005 Integration Services by Kirk Haselden that the BULK INSERT task was provided for backward compatibility and its use is disrecommended.

But after looking on the web I cannot find information supporting this.

Do you think the BULK INSERT task should be used for new development?

Thanks

It's not currently marked for deprecation. It may be in the future, because using the data flow and SQL Server Destinations or using the "fast load" option on the OLE DB destinations will be much more flexible.

I would avoid using the Bulk Insert Task simply because of its rigid restrictions and the fact that it requires a CSV formatted file. That's way too limiting for me.|||

I agree with you, the Data flow task is much more flexible. And it performed better than the BULK INSERT in my case...
But the big advantage of the BULK INSERT (and some see it as a disadvantage) is that it uses Format Files.

In our case, we have flat files from about 20 providers. There's is no way of suppling the Data flow task with a transformation schema, so that would mean creating/maintaining 20 different Data flow tasks (each in a different package).

Another implementation would be to use a generic SSIS with a Bulk Insert Task taking as parameters the source/destination and a format file. In that case, we would have to create/maintain 20 different format files.

So I'm currently weighting each option. The restrictions of the BULK INSERT such as the flat file requirement are not a problem in this case. Performance is at a certain extent. Usability, deployment and maintenance are the most important criteria.

Thanks!

|||You might want to provide feedback over on connect.microsoft.com and share your feelings.

Perhaps Matt Masson, Michael Entin, or others from MS can jump in and share their opinions or even MS' official stance.|||

Phil Brammer wrote:

You might want to provide feedback over on connect.microsoft.com and share your feelings.

Perhaps Matt Masson, Michael Entin, or others from MS can jump in and share their opinions or even MS' official stance.

Are you suggesting I ask them about the BULK INSERT being deprecated or about adding format file option to the Data flow task? I'm not sure...

What I would want is a place to seek advice on implementation. There's always many ways to do the same thing, especially when using T-SQL and SSIS. But do I post in the T-SQL forum or in the SSIS forum?

|||

fleo wrote:

Are you suggesting I ask them about the BULK INSERT being deprecated or about adding format file option to the Data flow task? I'm not sure...

What I would want is a place to seek advice on implementation. There's always many ways to do the same thing, especially when using T-SQL and SSIS. But do I post in the T-SQL forum or in the SSIS forum?

I'm suggesting that you post your feedback (via https://connect.microsoft.com/SQLServer/feedback)on how you want the BULK INSERT task to stick around and not be deprecated.

As far as which forum, well, that just depends on the scenario. Don't be too worried about which forum to post in as if we feel it needs to be moved, there are a few of us here that can do that accordingly.|||

There may have been deprecation discussions when Kirk was originally writing his book, but as of now, there are no plans to deprecate the Bulk Insert task.

As previously mentioned, you get more flexibility using the data flow approach, and if you’re able to use the “fast load” option, you might even get a 10-15% performance increase over the BULK INSERT tasks. You can weigh out both options, but as Phil has suggested, using a data flow is generally the recommended approach.

|||

I think the inflexibility is a decision point between using the Data Flow over the Bulk Insert Task and whilst I would normally use Data Flow perhaps more out of habit, I think fleo's point about being able to load files of any format, by dynamically setting properties is very valid.

It is something that cannot be achieved with the Data Flow task, and should not be underestimated. It can be a very powerful tool, and one reason why many people use the T-SQL equivalent or even BCP still. I just like being able to get that functionality within the SSIS framework so I can use configurations and logging and all that good stuff.

Use it and save time, and of course Matt has responded in the positive too!

|||

hI Matt,

so the Flat File Source has better performance than the BULK INSERT Task...

Where can I found this kind of information?

Also about the deprecation topic, why hasn't it written in the MSDN documentation?

Thank you

|||

Hi Antonio,

Unfortunately, the 10-15% performance increase that I quoted wasn't from any official testing or documentation... I believe it came from a developer from an internal group that was testing out both methods. There's typically a lot of variables involved in these tests, so I'd recommend trying out both approaches yourself and seeing which works best in your situation.

I'm not sure what you're asking about the deprecation topic. I wasn't able to find any official reference to the task being deprecated when I first looked into this, and MSDN typically doesn't explicitly mention that a task is NOT going to be deprecated.

Thanks,

~Matt

sql

BULK INSERT: high disk queues (SQL Server 2000 SP4)

Hi,
I am using BUK INSERT to fill a table that usually contains about 100
mio. rows with about 10000 new rows per batch. This usually works fine
and takes about 1-2 seconds. Such bulk insert operation is executed
about every five seconds.
The problem is, that after about every 2 minutes one bulk exec will
take about 75 seconds, causing enourmous disk queues. After that
everything is fine again - for about two minutes.
There are some other strange facts:
1) this behaviour did only show up after the installation of service
pack 4;
2) this behaviour usually vanished after a couple of days with
continuous bulk inserts and would then only show up again after a sql
server server restart (but currently I have one server that shows the
problem since three weeks already);
3) I have this behaviour on both of our production databases but on one
server it simply disappeared (but will probably be there again after a
server restart) and on the other server it won't go away now.
I am quiet desperate with this situation and would be most thankful for
any hint.
Regards
DCIs this slowdown and high disk queues associated with a checkpoint?
Checkthe Sql perfmon counter for Checkpoint Pages Per second.
Andrew J. Kelly SQL MVP
<dc@.upsize.de> wrote in message
news:1147686058.831935.28980@.v46g2000cwv.googlegroups.com...
> Hi,
> I am using BUK INSERT to fill a table that usually contains about 100
> mio. rows with about 10000 new rows per batch. This usually works fine
> and takes about 1-2 seconds. Such bulk insert operation is executed
> about every five seconds.
> The problem is, that after about every 2 minutes one bulk exec will
> take about 75 seconds, causing enourmous disk queues. After that
> everything is fine again - for about two minutes.
> There are some other strange facts:
> 1) this behaviour did only show up after the installation of service
> pack 4;
> 2) this behaviour usually vanished after a couple of days with
> continuous bulk inserts and would then only show up again after a sql
> server server restart (but currently I have one server that shows the
> problem since three weeks already);
> 3) I have this behaviour on both of our production databases but on one
> server it simply disappeared (but will probably be there again after a
> server restart) and on the other server it won't go away now.
> I am quiet desperate with this situation and would be most thankful for
> any hint.
> Regards
> DC
>|||Dear Andrew,
I added the counter and yes: the very moment when the disk queues
start, the number of checkpoints per seconds jumps right up from about
0-2 per second to a number of 500-1000 checkpoints per second. I don't
know what that means - but sure hope you have another clue for me.
Regards
DC|||May I add to this: the secondary server, which is identical (physical
and configuration-wise) to the queuing server and also receives the
exact same bulk inserts, does only show a few checkpoint pages per
second and only every few minutes for only two or three seconds.|||Are both databases using the same recovery model ..?
SELECT DATABASEPROPERTYEX('MyDatabase', 'Recovery')
Also, is the recovery interval the same for both databases, sp_configure
HTH. Ryan
<dc@.upsize.de> wrote in message
news:1147700793.823997.289510@.g10g2000cwb.googlegroups.com...
> May I add to this: the secondary server, which is identical (physical
> and configuration-wise) to the queuing server and also receives the
> exact same bulk inserts, does only show a few checkpoint pages per
> second and only every few minutes for only two or three seconds.
>|||Both servers use the simple recovery model.
sp_configure output is also identical on both server, recovery interval
(min) is set to the default 0.|||In simple recovery mode CHECKPOINT happens automatically when the log
reaches 70% full. Are the log files the same size ..?
dbcc sqlperf(logspace)
HTH. Ryan
<dc@.upsize.de> wrote in message
news:1147703050.779437.211430@.u72g2000cwu.googlegroups.com...
> Both servers use the simple recovery model.
> sp_configure output is also identical on both server, recovery interval
> (min) is set to the default 0.
>|||Both machines are configured to use up to 50 GB of logspace (on three
different harddrives; harddrive size and raid type is the same on both
boxes).
The server with the massive queuing currently utilizes only 500 MB of
transaction log size (and displays that 20% of that is being used),
while the server which is working fine utilizes 37 GB of log files (and
reports that 97% of that is being used).|||> The server with the massive queuing currently utilizes only 500 MB of
> transaction log size (and displays that 20% of that is being used),
> while the server which is working fine utilizes 37 GB of log files (and
> reports that 97% of that is being used).
Seems that the physical file size for the log files are not the same, and yo
u are seeing a side
effect of having a "too small" log file. SQL Server does a checkpoint when t
he log file is 70% full,
which turn out to be very frequently on the system with the smaller file. Gr
ow the file and you will
probably see a difference.
Good catch by Ryan, btw...
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
<dc@.upsize.de> wrote in message news:1147706961.661923.196630@.u72g2000cwu.googlegroups.com..
.
> Both machines are configured to use up to 50 GB of logspace (on three
> different harddrives; harddrive size and raid type is the same on both
> boxes).
> The server with the massive queuing currently utilizes only 500 MB of
> transaction log size (and displays that 20% of that is being used),
> while the server which is working fine utilizes 37 GB of log files (and
> reports that 97% of that is being used).
>|||How can I force the log file to grow? I thought it would grow
automatically on demand. Can I for example set the log file to a fixed
size?
BTW: I have been watching dbcc sqlperf(logspace) on the server with the
massive checkpoints and queueing. The log file utilization was growing
from around 10 to 20 percent when the queueing started - it definitely
did not hit 70%.

BULK INSERT: high disk queues (SQL Server 2000 SP4)

Hi,
I am using BUK INSERT to fill a table that usually contains about 100
mio. rows with about 10000 new rows per batch. This usually works fine
and takes about 1-2 seconds. Such bulk insert operation is executed
about every five seconds.
The problem is, that after about every 2 minutes one bulk exec will
take about 75 seconds, causing enourmous disk queues. After that
everything is fine again - for about two minutes.
There are some other strange facts:
1) this behaviour did only show up after the installation of service
pack 4;
2) this behaviour usually vanished after a couple of days with
continuous bulk inserts and would then only show up again after a sql
server server restart (but currently I have one server that shows the
problem since three weeks already);
3) I have this behaviour on both of our production databases but on one
server it simply disappeared (but will probably be there again after a
server restart) and on the other server it won't go away now.
I am quiet desperate with this situation and would be most thankful for
any hint.
Regards
DCIs this slowdown and high disk queues associated with a checkpoint?
Checkthe Sql perfmon counter for Checkpoint Pages Per second.
--
Andrew J. Kelly SQL MVP
<dc@.upsize.de> wrote in message
news:1147686058.831935.28980@.v46g2000cwv.googlegroups.com...
> Hi,
> I am using BUK INSERT to fill a table that usually contains about 100
> mio. rows with about 10000 new rows per batch. This usually works fine
> and takes about 1-2 seconds. Such bulk insert operation is executed
> about every five seconds.
> The problem is, that after about every 2 minutes one bulk exec will
> take about 75 seconds, causing enourmous disk queues. After that
> everything is fine again - for about two minutes.
> There are some other strange facts:
> 1) this behaviour did only show up after the installation of service
> pack 4;
> 2) this behaviour usually vanished after a couple of days with
> continuous bulk inserts and would then only show up again after a sql
> server server restart (but currently I have one server that shows the
> problem since three weeks already);
> 3) I have this behaviour on both of our production databases but on one
> server it simply disappeared (but will probably be there again after a
> server restart) and on the other server it won't go away now.
> I am quiet desperate with this situation and would be most thankful for
> any hint.
> Regards
> DC
>|||Dear Andrew,
I added the counter and yes: the very moment when the disk queues
start, the number of checkpoints per seconds jumps right up from about
0-2 per second to a number of 500-1000 checkpoints per second. I don't
know what that means - but sure hope you have another clue for me.
Regards
DC|||May I add to this: the secondary server, which is identical (physical
and configuration-wise) to the queuing server and also receives the
exact same bulk inserts, does only show a few checkpoint pages per
second and only every few minutes for only two or three seconds.|||Are both databases using the same recovery model ..?
SELECT DATABASEPROPERTYEX('MyDatabase', 'Recovery')
Also, is the recovery interval the same for both databases, sp_configure
--
HTH. Ryan
<dc@.upsize.de> wrote in message
news:1147700793.823997.289510@.g10g2000cwb.googlegroups.com...
> May I add to this: the secondary server, which is identical (physical
> and configuration-wise) to the queuing server and also receives the
> exact same bulk inserts, does only show a few checkpoint pages per
> second and only every few minutes for only two or three seconds.
>|||Both servers use the simple recovery model.
sp_configure output is also identical on both server, recovery interval
(min) is set to the default 0.|||In simple recovery mode CHECKPOINT happens automatically when the log
reaches 70% full. Are the log files the same size ..?
dbcc sqlperf(logspace)
HTH. Ryan
<dc@.upsize.de> wrote in message
news:1147703050.779437.211430@.u72g2000cwu.googlegroups.com...
> Both servers use the simple recovery model.
> sp_configure output is also identical on both server, recovery interval
> (min) is set to the default 0.
>|||Both machines are configured to use up to 50 GB of logspace (on three
different harddrives; harddrive size and raid type is the same on both
boxes).
The server with the massive queuing currently utilizes only 500 MB of
transaction log size (and displays that 20% of that is being used),
while the server which is working fine utilizes 37 GB of log files (and
reports that 97% of that is being used).|||> The server with the massive queuing currently utilizes only 500 MB of
> transaction log size (and displays that 20% of that is being used),
> while the server which is working fine utilizes 37 GB of log files (and
> reports that 97% of that is being used).
Seems that the physical file size for the log files are not the same, and you are seeing a side
effect of having a "too small" log file. SQL Server does a checkpoint when the log file is 70% full,
which turn out to be very frequently on the system with the smaller file. Grow the file and you will
probably see a difference.
Good catch by Ryan, btw...
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
<dc@.upsize.de> wrote in message news:1147706961.661923.196630@.u72g2000cwu.googlegroups.com...
> Both machines are configured to use up to 50 GB of logspace (on three
> different harddrives; harddrive size and raid type is the same on both
> boxes).
> The server with the massive queuing currently utilizes only 500 MB of
> transaction log size (and displays that 20% of that is being used),
> while the server which is working fine utilizes 37 GB of log files (and
> reports that 97% of that is being used).
>|||How can I force the log file to grow? I thought it would grow
automatically on demand. Can I for example set the log file to a fixed
size?
BTW: I have been watching dbcc sqlperf(logspace) on the server with the
massive checkpoints and queueing. The log file utilization was growing
from around 10 to 20 percent when the queueing started - it definitely
did not hit 70%.|||If you do enough changes the recovery interval can force a checkpoint before
the 70% fullness is reached. You can change the size of the log file with
alter database command or thru Enterprise Manager. I would make both of them
the same size so you can rule that part out. Just because the machines seem
identical they may not be. One thing that affects how long a checkpoint
takes is the size and configuration of the cache on the disk controllers or
the SAN. IS the cache the same on both servers? Do you have write back
cache enabled and if so what is the read to write ratio?
--
Andrew J. Kelly SQL MVP
<dc@.upsize.de> wrote in message
news:1147726750.397611.19450@.i39g2000cwa.googlegroups.com...
> How can I force the log file to grow? I thought it would grow
> automatically on demand. Can I for example set the log file to a fixed
> size?
> BTW: I have been watching dbcc sqlperf(logspace) on the server with the
> massive checkpoints and queueing. The log file utilization was growing
> from around 10 to 20 percent when the queueing started - it definitely
> did not hit 70%.
>|||A slightly different approach would be to take control of the CHECKPOINT
yourself.
Try a different batch size (say 1000) and issue a CHECKPOINT after each
batch, that way the disk controller should receive a steady trickle of data
rather than being swamped
--
HTH. Ryan
"Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
news:ePFexUGeGHA.2188@.TK2MSFTNGP05.phx.gbl...
> If you do enough changes the recovery interval can force a checkpoint
> before the 70% fullness is reached. You can change the size of the log
> file with alter database command or thru Enterprise Manager. I would make
> both of them the same size so you can rule that part out. Just because the
> machines seem identical they may not be. One thing that affects how long a
> checkpoint takes is the size and configuration of the cache on the disk
> controllers or the SAN. IS the cache the same on both servers? Do you
> have write back cache enabled and if so what is the read to write ratio?
> --
> Andrew J. Kelly SQL MVP
>
> <dc@.upsize.de> wrote in message
> news:1147726750.397611.19450@.i39g2000cwa.googlegroups.com...
>> How can I force the log file to grow? I thought it would grow
>> automatically on demand. Can I for example set the log file to a fixed
>> size?
>> BTW: I have been watching dbcc sqlperf(logspace) on the server with the
>> massive checkpoints and queueing. The log file utilization was growing
>> from around 10 to 20 percent when the queueing started - it definitely
>> did not hit 70%.
>|||Coincidentally this morning the queueing on the problematic server has
disappeared. Without obvious reason, after three weeks of problems.
However, I am sure that the problems will reappear once I restart the
server, since that has happened in the past.
When I manually launch a CHECKPOINT command on the server, it will
queue for about five minutes. And when I launch another checkpoint just
a few seconds later, it will again cause the disks to spin for a couple
of minutes.
dbcc sqlperf(logspace) now shows, that the database on the problematic
server is using 20 GB of log space. Maybe
ALTER DATABASE MyDB
MODIFY FILE
(NAME = MyLogfile,
SIZE = 40GB)
will help to avoid the automatic checkpoints once I have to restart one
of the servers.
I will also try to install the post SP4 hotfixes next time. I think
that these bulk insert related queues / checkpoints are a buggy sql
server behaviour since it did not appear before SP4.|||Today the problematic server started unwanted checkpoints and queueing
again. Which is strange, since in the past the servers were fine once
the queueing ceased - until the server had to be restarted.
I increased the logfile size with ALTER DATABASE - no change. I
installed the post-SP4 hotfixed - still no success.
The only countermeasure that had an effect is
sp_configure "recovery_interval", 60
RECONFIGURE WITH OVERRIDE
but this will still result in longer (about 3 minutes) queueing in
bigger intervals (~20 minutes).
Can I somehow find out what exactly is causing the checkpoint? Can I
see the checkpoint time and reason somewhere in the system tables? The
only difference between the two servers that I can see now, is that the
problematic server uses only a few percent of logspace (never hitting
70%), while the OK server always uses > 95% of the log space.
It is too bad that I cannot use non-logged or minimally-logged BULK
INSERTS (I cannot use TABLOCK because the table is also permanently
being queryied) since I believe that would make a difference in my
scenario.
I am wondering if SQL Server 2005 will perform better in my scenario
with permanent bulk inserts and also massive updating and simultaneous
querying. Data integrity is really not that important for my
application, but speed is. I wish I could deactivate all logging.|||Are you sure they are all in the same recovery model? In any case I really
think you are going down the wrong road. The bottom line is that if
checkpoints cause too much pain and last too long you do not have a proper
disk subsystem or configuration to handle the load.IS the log file on a RAID
1 or RAID 10 with no other types of files? What is the array configuration
for the data? How much and what is the configuration for the cache on the
controller or SAN processor?
--
Andrew J. Kelly SQL MVP
<dc@.upsize.de> wrote in message
news:1147959206.497801.43880@.j55g2000cwa.googlegroups.com...
> Today the problematic server started unwanted checkpoints and queueing
> again. Which is strange, since in the past the servers were fine once
> the queueing ceased - until the server had to be restarted.
> I increased the logfile size with ALTER DATABASE - no change. I
> installed the post-SP4 hotfixed - still no success.
> The only countermeasure that had an effect is
> sp_configure "recovery_interval", 60
> RECONFIGURE WITH OVERRIDE
> but this will still result in longer (about 3 minutes) queueing in
> bigger intervals (~20 minutes).
> Can I somehow find out what exactly is causing the checkpoint? Can I
> see the checkpoint time and reason somewhere in the system tables? The
> only difference between the two servers that I can see now, is that the
> problematic server uses only a few percent of logspace (never hitting
> 70%), while the OK server always uses > 95% of the log space.
> It is too bad that I cannot use non-logged or minimally-logged BULK
> INSERTS (I cannot use TABLOCK because the table is also permanently
> being queryied) since I believe that would make a difference in my
> scenario.
> I am wondering if SQL Server 2005 will perform better in my scenario
> with permanent bulk inserts and also massive updating and simultaneous
> querying. Data integrity is really not that important for my
> application, but speed is. I wish I could deactivate all logging.
>|||====================================="Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
news:#jJQM#teGHA.4828@.TK2MSFTNGP05.phx.gbl...
> Are you sure they are all in the same recovery model? In any case I
really
> think you are going down the wrong road. The bottom line is that if
> checkpoints cause too much pain and last too long you do not have a proper
> disk subsystem or configuration to handle the load.IS the log file on a
RAID
> 1 or RAID 10 with no other types of files? What is the array
configuration
> for the data? How much and what is the configuration for the cache on the
> controller or SAN processor?
> --
> Andrew J. Kelly SQL MVP
>
> <dc@.upsize.de> wrote in message
> news:1147959206.497801.43880@.j55g2000cwa.googlegroups.com...
> > Today the problematic server started unwanted checkpoints and queueing
> > again. Which is strange, since in the past the servers were fine once
> > the queueing ceased - until the server had to be restarted.
> >
> > I increased the logfile size with ALTER DATABASE - no change. I
> > installed the post-SP4 hotfixed - still no success.
> >
> > The only countermeasure that had an effect is
> >
> > sp_configure "recovery_interval", 60
> >
> > RECONFIGURE WITH OVERRIDE
> >
> > but this will still result in longer (about 3 minutes) queueing in
> > bigger intervals (~20 minutes).
> >
> > Can I somehow find out what exactly is causing the checkpoint? Can I
> > see the checkpoint time and reason somewhere in the system tables? The
> > only difference between the two servers that I can see now, is that the
> > problematic server uses only a few percent of logspace (never hitting
> > 70%), while the OK server always uses > 95% of the log space.
> >
> > It is too bad that I cannot use non-logged or minimally-logged BULK
> > INSERTS (I cannot use TABLOCK because the table is also permanently
> > being queryied) since I believe that would make a difference in my
> > scenario.
> >
> > I am wondering if SQL Server 2005 will perform better in my scenario
> > with permanent bulk inserts and also massive updating and simultaneous
> > querying. Data integrity is really not that important for my
> > application, but speed is. I wish I could deactivate all logging.
> >
>|||I am ruling out disk performance, since the problem occurs on two
servers with identical hardware and configuration (including recovery
model) and it only occurs after the servers have been restarted. And on
one of the servers the problem seems to have manifested since it is
still there even weeks after restarting.
I never had this "too many checkpoints" problem before SP4. I am
thinking about going back to SP3. However, if I could somehow diagnose
why the checkpoints are occuring that would help. As mentioned before,
the situation got better with changing the "recovery_interval" to 300.
However, if I change the interval to 3000 or 30000 that does not seem
to make much of a difference, still a checkpoint will occur in 20-30
minute intervals.|||I'm not sure if this posted since it's been over 10 minutes and I got a blank
page after clicking the post button, so please ignore if my response is
already there:
Just out of curiosity, is there any reason why you're using the Simple
Recovery Model on a Production server that also receives a majority of their
inserts through Bulk-Insert? Why aren't you using the Bulk-Logged Recovery
Model which is designed for this particular situation? Each time you do a
Bulk-Insert of any magnitude, it is being logged, which will cause your
transaction logs to grow because each row that's being inserted is being
recorded, whereas using the Bulk-Logged Recovery will only record that you're
doing a Bulk-Insert, which will be less writes to your transaction log, less
auto-growth, and possibly less automatic checkpoints. I would follow the
suggestion of doing a manual checkpoint before each Bulk-Insert for piece of
mind though. Hopefully this helps.
Laurence
"Andrew J. Kelly" wrote:
> Are you sure they are all in the same recovery model? In any case I really
> think you are going down the wrong road. The bottom line is that if
> checkpoints cause too much pain and last too long you do not have a proper
> disk subsystem or configuration to handle the load.IS the log file on a RAID
> 1 or RAID 10 with no other types of files? What is the array configuration
> for the data? How much and what is the configuration for the cache on the
> controller or SAN processor?
> --
> Andrew J. Kelly SQL MVP
>
> <dc@.upsize.de> wrote in message
> news:1147959206.497801.43880@.j55g2000cwa.googlegroups.com...
> > Today the problematic server started unwanted checkpoints and queueing
> > again. Which is strange, since in the past the servers were fine once
> > the queueing ceased - until the server had to be restarted.
> >
> > I increased the logfile size with ALTER DATABASE - no change. I
> > installed the post-SP4 hotfixed - still no success.
> >
> > The only countermeasure that had an effect is
> >
> > sp_configure "recovery_interval", 60
> >
> > RECONFIGURE WITH OVERRIDE
> >
> > but this will still result in longer (about 3 minutes) queueing in
> > bigger intervals (~20 minutes).
> >
> > Can I somehow find out what exactly is causing the checkpoint? Can I
> > see the checkpoint time and reason somewhere in the system tables? The
> > only difference between the two servers that I can see now, is that the
> > problematic server uses only a few percent of logspace (never hitting
> > 70%), while the OK server always uses > 95% of the log space.
> >
> > It is too bad that I cannot use non-logged or minimally-logged BULK
> > INSERTS (I cannot use TABLOCK because the table is also permanently
> > being queryied) since I believe that would make a difference in my
> > scenario.
> >
> > I am wondering if SQL Server 2005 will perform better in my scenario
> > with permanent bulk inserts and also massive updating and simultaneous
> > querying. Data integrity is really not that important for my
> > application, but speed is. I wish I could deactivate all logging.
> >
>
>|||It is always OK for us to go back to the last backup. I thought that in
that scenario "simple" is the least demanding recovery model in terms
of logging. My understanding is that "bulk logged" mimics "simple" for
the bulk operations, but "full" for other operations. Since one of our
tables also receives a massive amount of updates, "bulk logged" mode
should result in more log file action.
However, out of desperation I switched to "bulk logged" on the
problematic server. That did not fix the problem, there is still a
checkpoint about every two minutes. I am currently working around by
setting the recovery_interval to 32767, which will still issue a
checkpoint or two per day and then block the server for about five
minutes (I wonder why the checkpoint does not take 32767 minutes since
that is what I thought the recovery_interval option indicates). I am
quiet sure that it will not take my database 32767 minutes to recover
after restarting the server but I am not willing to try.
I think that Sql Server is not calculating the time for a checkpoint
correctly under some circumstances with SP4 (don't know what exactly
the circumstances are since the other server is still operating
perfectly). I believe that the rows inserted with a bulk insert should
not trigger a checkpoint as quickly as they currently do, in other
words (sorry for my naive assumption) Sql Server takes to bulk inserted
rows for a reason to make a checkpoint appear.
Laurence schrieb:
> I'm not sure if this posted since it's been over 10 minutes and I got a blank
> page after clicking the post button, so please ignore if my response is
> already there:
> Just out of curiosity, is there any reason why you're using the Simple
> Recovery Model on a Production server that also receives a majority of their
> inserts through Bulk-Insert? Why aren't you using the Bulk-Logged Recovery
> Model which is designed for this particular situation? Each time you do a
> Bulk-Insert of any magnitude, it is being logged, which will cause your
> transaction logs to grow because each row that's being inserted is being
> recorded, whereas using the Bulk-Logged Recovery will only record that you're
> doing a Bulk-Insert, which will be less writes to your transaction log, less
> auto-growth, and possibly less automatic checkpoints. I would follow the
> suggestion of doing a manual checkpoint before each Bulk-Insert for piece of
> mind though. Hopefully this helps.
> Laurence
> "Andrew J. Kelly" wrote:
> > Are you sure they are all in the same recovery model? In any case I really
> > think you are going down the wrong road. The bottom line is that if
> > checkpoints cause too much pain and last too long you do not have a proper
> > disk subsystem or configuration to handle the load.IS the log file on a RAID
> > 1 or RAID 10 with no other types of files? What is the array configuration
> > for the data? How much and what is the configuration for the cache on the
> > controller or SAN processor?
> >
> > --
> > Andrew J. Kelly SQL MVP
> >
> >
> > <dc@.upsize.de> wrote in message
> > news:1147959206.497801.43880@.j55g2000cwa.googlegroups.com...
> > > Today the problematic server started unwanted checkpoints and queueing
> > > again. Which is strange, since in the past the servers were fine once
> > > the queueing ceased - until the server had to be restarted.
> > >
> > > I increased the logfile size with ALTER DATABASE - no change. I
> > > installed the post-SP4 hotfixed - still no success.
> > >
> > > The only countermeasure that had an effect is
> > >
> > > sp_configure "recovery_interval", 60
> > >
> > > RECONFIGURE WITH OVERRIDE
> > >
> > > but this will still result in longer (about 3 minutes) queueing in
> > > bigger intervals (~20 minutes).
> > >
> > > Can I somehow find out what exactly is causing the checkpoint? Can I
> > > see the checkpoint time and reason somewhere in the system tables? The
> > > only difference between the two servers that I can see now, is that the
> > > problematic server uses only a few percent of logspace (never hitting
> > > 70%), while the OK server always uses > 95% of the log space.
> > >
> > > It is too bad that I cannot use non-logged or minimally-logged BULK
> > > INSERTS (I cannot use TABLOCK because the table is also permanently
> > > being queryied) since I believe that would make a difference in my
> > > scenario.
> > >
> > > I am wondering if SQL Server 2005 will perform better in my scenario
> > > with permanent bulk inserts and also massive updating and simultaneous
> > > querying. Data integrity is really not that important for my
> > > application, but speed is. I wish I could deactivate all logging.
> > >
> >
> >
> >|||Hi
Don't forget, a checkpoint is a flush of dirty buffers to disk. This flush
will take a lot less time than the recovery interval setting. The recovery
interval setting is based on a log replay, not a simple flush to disk.
The amount of available RAM also play a role in the checkpoint interval
(e.g. if your DB is 20GB, and you have 2GB buffer RAM, if every page was
modified, ideally at least 10 checkpoints have to occur). If you are in
simple recovery mode, 70% log full generates a checkpoint.
Making sure that your disk subsystem is optimal is the answer to checkpoint
performance problems. Andrew listed the points to look for.
--
Mike
This posting is provided "AS IS" with no warranties, and confers no rights.
<dc@.upsize.de> wrote in message
news:1149591061.614095.295260@.f6g2000cwb.googlegroups.com...
> It is always OK for us to go back to the last backup. I thought that in
> that scenario "simple" is the least demanding recovery model in terms
> of logging. My understanding is that "bulk logged" mimics "simple" for
> the bulk operations, but "full" for other operations. Since one of our
> tables also receives a massive amount of updates, "bulk logged" mode
> should result in more log file action.
> However, out of desperation I switched to "bulk logged" on the
> problematic server. That did not fix the problem, there is still a
> checkpoint about every two minutes. I am currently working around by
> setting the recovery_interval to 32767, which will still issue a
> checkpoint or two per day and then block the server for about five
> minutes (I wonder why the checkpoint does not take 32767 minutes since
> that is what I thought the recovery_interval option indicates). I am
> quiet sure that it will not take my database 32767 minutes to recover
> after restarting the server but I am not willing to try.
> I think that Sql Server is not calculating the time for a checkpoint
> correctly under some circumstances with SP4 (don't know what exactly
> the circumstances are since the other server is still operating
> perfectly). I believe that the rows inserted with a bulk insert should
> not trigger a checkpoint as quickly as they currently do, in other
> words (sorry for my naive assumption) Sql Server takes to bulk inserted
> rows for a reason to make a checkpoint appear.
>
> Laurence schrieb:
>> I'm not sure if this posted since it's been over 10 minutes and I got a
>> blank
>> page after clicking the post button, so please ignore if my response is
>> already there:
>> Just out of curiosity, is there any reason why you're using the Simple
>> Recovery Model on a Production server that also receives a majority of
>> their
>> inserts through Bulk-Insert? Why aren't you using the Bulk-Logged
>> Recovery
>> Model which is designed for this particular situation? Each time you do
>> a
>> Bulk-Insert of any magnitude, it is being logged, which will cause your
>> transaction logs to grow because each row that's being inserted is being
>> recorded, whereas using the Bulk-Logged Recovery will only record that
>> you're
>> doing a Bulk-Insert, which will be less writes to your transaction log,
>> less
>> auto-growth, and possibly less automatic checkpoints. I would follow the
>> suggestion of doing a manual checkpoint before each Bulk-Insert for piece
>> of
>> mind though. Hopefully this helps.
>> Laurence
>> "Andrew J. Kelly" wrote:
>> > Are you sure they are all in the same recovery model? In any case I
>> > really
>> > think you are going down the wrong road. The bottom line is that if
>> > checkpoints cause too much pain and last too long you do not have a
>> > proper
>> > disk subsystem or configuration to handle the load.IS the log file on a
>> > RAID
>> > 1 or RAID 10 with no other types of files? What is the array
>> > configuration
>> > for the data? How much and what is the configuration for the cache on
>> > the
>> > controller or SAN processor?
>> >
>> > --
>> > Andrew J. Kelly SQL MVP
>> >
>> >
>> > <dc@.upsize.de> wrote in message
>> > news:1147959206.497801.43880@.j55g2000cwa.googlegroups.com...
>> > > Today the problematic server started unwanted checkpoints and
>> > > queueing
>> > > again. Which is strange, since in the past the servers were fine once
>> > > the queueing ceased - until the server had to be restarted.
>> > >
>> > > I increased the logfile size with ALTER DATABASE - no change. I
>> > > installed the post-SP4 hotfixed - still no success.
>> > >
>> > > The only countermeasure that had an effect is
>> > >
>> > > sp_configure "recovery_interval", 60
>> > >
>> > > RECONFIGURE WITH OVERRIDE
>> > >
>> > > but this will still result in longer (about 3 minutes) queueing in
>> > > bigger intervals (~20 minutes).
>> > >
>> > > Can I somehow find out what exactly is causing the checkpoint? Can I
>> > > see the checkpoint time and reason somewhere in the system tables?
>> > > The
>> > > only difference between the two servers that I can see now, is that
>> > > the
>> > > problematic server uses only a few percent of logspace (never hitting
>> > > 70%), while the OK server always uses > 95% of the log space.
>> > >
>> > > It is too bad that I cannot use non-logged or minimally-logged BULK
>> > > INSERTS (I cannot use TABLOCK because the table is also permanently
>> > > being queryied) since I believe that would make a difference in my
>> > > scenario.
>> > >
>> > > I am wondering if SQL Server 2005 will perform better in my scenario
>> > > with permanent bulk inserts and also massive updating and
>> > > simultaneous
>> > > querying. Data integrity is really not that important for my
>> > > application, but speed is. I wish I could deactivate all logging.
>> > >
>> >
>> >
>> >
>|||rahul sharma
rahul.sharma822@.gmail.com
*** Sent via Developersdex http://www.developersdex.com ***

Bulk Insert/Update Ideas

I need a fresh set of eyes.

On a daily basis I need to perform a bulk update. Table totals about 50,000 records with approximately 5,000 changing (deletes, edits, and new records) per day. I'd like to push just the updates somehow, but VB is too slow and I haven't found a way in to handle it in DTS. Not much experience w/ DTS.

I'm transfering between two SQL 2000 servers w/ a VB app sitting in the middle.

Any ideas?you can break the incoming file into 3 corresponding to operations (insert, update, delete) using findstr with redirection (>)

then for insert you just do a straight bulk insert, while for update and delete do a bulk insert into a staging table and then delete and update by joining it with the live table.

Bulk Insert/ one column

I have no problem importing a file.txt to my table (mehet).

Bulk Insert mehet From 'C:\test.txt'

With (DataFileType = 'char', FIELDTERMINATOR = ',')

But I would appreciated if someone could help me how to import only 1 or 2 columns.

instead of all columns.

Thanks.

juvan

hi,

you can perhaps have a look at format file support, that can be used by BULK operations..

define a file to be imported, say
d:\imp\data.txt like
[d:\imp\data.txt]
Andrea,Montanari,5
Juvan,Juvan,2
[/d:\imp\data.txt]

you can then use a format file to specify the required mappings... define a first one like
[fmt.txt]
9.0
3
1 SQLCHAR 0 10 "," 1 lName ""
2 SQLCHAR 0 10 "," 2 fName ""
3 SQLCHAR 0 7 "\r\n" 3 Id ""
[/fmt.txt]

define another fmt file like

[fmt2.txt]
9.0
3
1 SQLCHAR 0 10 "," 1 lName ""
2 SQLCHAR 0 10 "," 2 fName ""
3 SQLCHAR 0 7 "\r\n" 0 Id ""
[/fmt2.txt]

all included columns will be mapped to a column of the target table (see SQL script);

SET NOCOUNT ON;

USE tempdb;

GO

CREATE TABLE dbo.Test (

fName varchar(10),

lName varchar(10) DEFAULT 'not set',

Id int DEFAULT -1000

);

GO

BULK INSERT dbo.Test

FROM 'd:\imp\Data.txt'

WITH (formatfile='d:\imp\fmt.txt');

SELECT * FROM dbo.Test;

GO

PRINT 'modify the fmt file putting 0 in the ID column as fmt2.txt';

BULK INSERT dbo.Test

FROM 'd:\imp\Data.txt'

WITH (formatfile='d:\imp\fmt2.txt');

SELECT * FROM dbo.Test;

GO

PRINT 'just use an INSERT ... specifying the required colums';

SELECT lName

FROM OPENROWSET(BULK 'd:\imp\Data.txt',

FORMATFILE='d:\imp\fmt2.txt'

) AS t1;

INSERT INTO dbo.Test (fName)

SELECT lName

FROM OPENROWSET(BULK 'd:\imp\Data.txt',

FORMATFILE='d:\imp\fmt2.txt'

) AS t1;

SELECT * FROM dbo.Test;

GO

DROP TABLE dbo.Test;

--<-

fName lName Id

- - --

Andrea Montanari 5

Juvan Juvan 2

modify the fmt file putting 0 in the ID column as fmt2.txt

fName lName Id

- - --

Andrea Montanari 5

Juvan Juvan 2

Andrea Montanari -1000

Juvan Juvan -1000

just use an INSERT ... specifying the required colums

lName

-

Andrea

Juvan

fName lName Id

- - --

Andrea Montanari 5

Juvan Juvan 2

Andrea Montanari -1000

Juvan Juvan -1000

Andrea not set -1000

Juvan not set -1000

as you can see, you can play with the fmt file as required, excluding unwanted colums at the retrival source time, or later if you just use an INSERT SELECT FROM OPENROWSET..

regards

|||

Hi Andrea,

Thanks for your help. I got it right thanks to you.

I have one more question, if you don't mind?

Sometimes I go out of town where there has no internet. It is possible to connect to my Database at home by using

phoneline direct? If there is a way, Can you let me know please.

Thanks.

Juvan

|||

hi,

you can connect over the net to your server from your home pc... but a direct SQL Server service open over the internet is not that secure... you should eventually read about V(irtual) P(rivate) N(etwork) connections to protect your server and not to allow someone to just open a connection over your TCP/IP xxx-xxx-x-xxx IP address ...

stay secure as you can

regards

|||

hi,

Yes, but as I have said that the area where I go to has no internet connection at all. So in this case what should I do?

Thanks.

Juvan

Bulk Insert.

Is there any way I can use the following command like that ?
BULK INSERT Northwind.dbo.[Order Details]
FROM (select CSVTextFile from tblCSV)
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
Thanks in advance
The syntax of BULK INSERT is
quote:

BULK INSERT [ [ 'database_name'.] [ 'owner' ].] { 'table_name' FROM
'data_file' }...
'data_file'
Is the full path of the data file that contains data to copy into the
specified table or view. BULK INSERT can copy data from a disk (including
network, floppy disk, hard disk, and so on).
data_file must specify a valid path from the server on which SQL Server is
running. If data_file is a remote file, specify the Universal Naming
Convention (UNC) name.


Please refer to Books Online for examples of how to use BULK INSERT
http://msdn.microsoft.com/library/de...ba-bz_4fec.asp
Cristian Lefter, SQL Server MVP
MCT, MCSA, MCDBA, MCAD, MCSD .NET
"Rogers" <Rogers@.mailstuff.com> wrote in message
news:Oyx71bHuFHA.2624@.TK2MSFTNGP12.phx.gbl...
> Is there any way I can use the following command like that ?
> BULK INSERT Northwind.dbo.[Order Details]
> FROM (select CSVTextFile from tblCSV)
> WITH
> (
> FIELDTERMINATOR = ',',
> ROWTERMINATOR = '\n'
> )
> Thanks in advance
>
sql

Bulk insert, skip rows with duplicate key error?

Does sql server have a way to handle errors in a sproc which would allow
one to insert rows, ignoring rows which would create a duplicate key
violation? I know if one loops one can handle the error on a row by row
basis. But is there a way to skip the loop and do it as a bulk insert?
It's easy to do in Access, but I'm curious to know if SQL Server proper
can handle like this. I am guessing that a looping operation would be
slower to execute?nano (nano@.nano.ono) writes:

Quote:

Originally Posted by

Does sql server have a way to handle errors in a sproc which would allow
one to insert rows, ignoring rows which would create a duplicate key
violation? I know if one loops one can handle the error on a row by row
basis. But is there a way to skip the loop and do it as a bulk insert?
It's easy to do in Access, but I'm curious to know if SQL Server proper
can handle like this. I am guessing that a looping operation would be
slower to execute?


I'm a little uncertain what you are talking about. In SQL Server "bulk
insert" is a special operation where you load many rows direct from a
file. Or are you still talking about regular SQL statements?

In the latter case, use

INSERT tbl
SELECT ...
FROM src
WHERE NOT EXISTS (SELECT *
FROM tbl
WHERE tbl.keycol = src.keycol)

which should be the normal way to do it in Access - or any other SQL engine
for that matter - as well.

If you are specifically talking bulk load from file, then above is still
possible in SQL 2005 if you use OPENROWSET(BULK) as the table source. If
you use BULK INSERT or BCP (the only options on SQL 2000), I believe it's
possible by using the IGNORE_DUP_KEY option on the index, but a more
common procedure is to load the file to staging table and move on from
there.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Thanks Erland. I meant a regular sql operation. I will take a look at
your suggestion, it looks good. Access has another way of handling this
(non-sql) and while the syntax you suggest probably works in Access,
I've never tried it.