PC Review


Reply
Thread Tools Rate Thread

A question on SQLBulkCopy.

 
 
George Shui
Guest
Posts: n/a
 
      11th May 2008
The database I use is SQL Server 2005.

The user to login database is 'PG_TestUser', it has 'dbo' schema, and it has
datareader and datawriter permission.

I have .NET Code like this.

using (SqlBulkCopy bulkCopy = new SqlBulkCopy(dbConnStr,
SqlBulkCopyOptions.KeepIdentity | SqlBulkCopyOptions.UseInternalTransaction))
{
bulkCopy.DestinationTableName = tableName.Trim();

DataTable dt = CSVFileHelper.Read(dataFile);

bulkCopy.BulkCopyTimeout = Const.TIMEOUT;

bulkCopy.WriteToServer(dt);
}

But I have got the exception "Cannot find the object "SVSReportDetail"
because it does not exist or you do not have permissions"

The stackTrace is:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception,
Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
exception, Boolean breakConnection)
at
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,
SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet
bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlBulkCopy.WriteToServerInternal()
at System.Data.SqlClient.SqlBulkCopy.WriteRowSourceToServer(Int32
columnCount)
at System.Data.SqlClient.SqlBulkCopy.WriteToServer(DataTable table,
DataRowState rowState)
at System.Data.SqlClient.SqlBulkCopy.WriteToServer(DataTable table)
at DBArchiveManager.AbstractImportPorcessor.BulkImport(String dbConnStr,
String tableName, FileInfo dataFile) in
D:\WebRoot\PGS\Tool\DBArchiveManager.root\DBArchiveManager\DBArchiveManager\Processor\ImportProcessor\AbstractImportPorcessor.cs:line 56

If I gave the 'PG_TestUser' the 'sysadmin' schema, the code works.
Also I have tried that the 'PG_TestUser' do have the select, delete, insert
permision.

AnyOne can help me?

Thank you for your help in advance.





 
Reply With Quote
 
 
 
 
George Shui
Guest
Posts: n/a
 
      11th May 2008
Sure. This table do exist. And The user can do Select, Insert, Delete on this
table.

Another point is If I gave the user the 'sysadmin', my code can work.

Thanks.

 
Reply With Quote
 
SM
Guest
Posts: n/a
 
      24th Nov 2009
Assigning ddladmin or db_owner database role should fix issue.



GeorgeShu wrote:

A question on SQLBulkCopy.
11-May-08

The database I use is SQL Server 2005.

The user to login database is 'PG_TestUser', it has 'dbo' schema, and it has
datareader and datawriter permission

I have .NET Code like this

using (SqlBulkCopy bulkCopy = new SqlBulkCopy(dbConnStr,
SqlBulkCopyOptions.KeepIdentity | SqlBulkCopyOptions.UseInternalTransaction)

bulkCopy.DestinationTableName = tableName.Trim()

DataTable dt = CSVFileHelper.Read(dataFile)

bulkCopy.BulkCopyTimeout = Const.TIMEOUT

bulkCopy.WriteToServer(dt)


But I have got the exception "Cannot find the object "SVSReportDetail"
because it does not exist or you do not have permissions

The stackTrace is
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception,
Boolean breakConnection
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
exception, Boolean breakConnection
at
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
stateObj
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,
SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet
bulkCopyHandler, TdsParserStateObject stateObj
at System.Data.SqlClient.SqlBulkCopy.WriteToServerInternal(
at System.Data.SqlClient.SqlBulkCopy.WriteRowSourceToServer(Int32
columnCount
at System.Data.SqlClient.SqlBulkCopy.WriteToServer(DataTable table,
DataRowState rowState
at System.Data.SqlClient.SqlBulkCopy.WriteToServer(DataTable table
at DBArchiveManager.AbstractImportPorcessor.BulkImport(String dbConnStr,
String tableName, FileInfo dataFile) in
D:\WebRoot\PGS\Tool\DBArchiveManager.root\DBArchiveManager\DBArchiveManager\Processor\ImportProcessor\AbstractImportPorcessor.cs:line 5

If I gave the 'PG_TestUser' the 'sysadmin' schema, the code works
Also I have tried that the 'PG_TestUser' do have the select, delete, insert
permision

AnyOne can help me

Thank you for your help in advance.

Previous Posts In This Thread:

On Sunday, May 11, 2008 3:55 PM
GeorgeShu wrote:

A question on SQLBulkCopy.
The database I use is SQL Server 2005.

The user to login database is 'PG_TestUser', it has 'dbo' schema, and it has
datareader and datawriter permission

I have .NET Code like this

using (SqlBulkCopy bulkCopy = new SqlBulkCopy(dbConnStr,
SqlBulkCopyOptions.KeepIdentity | SqlBulkCopyOptions.UseInternalTransaction)

bulkCopy.DestinationTableName = tableName.Trim()

DataTable dt = CSVFileHelper.Read(dataFile)

bulkCopy.BulkCopyTimeout = Const.TIMEOUT

bulkCopy.WriteToServer(dt)


But I have got the exception "Cannot find the object "SVSReportDetail"
because it does not exist or you do not have permissions

The stackTrace is
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception,
Boolean breakConnection
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
exception, Boolean breakConnection
at
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
stateObj
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,
SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet
bulkCopyHandler, TdsParserStateObject stateObj
at System.Data.SqlClient.SqlBulkCopy.WriteToServerInternal(
at System.Data.SqlClient.SqlBulkCopy.WriteRowSourceToServer(Int32
columnCount
at System.Data.SqlClient.SqlBulkCopy.WriteToServer(DataTable table,
DataRowState rowState
at System.Data.SqlClient.SqlBulkCopy.WriteToServer(DataTable table
at DBArchiveManager.AbstractImportPorcessor.BulkImport(String dbConnStr,
String tableName, FileInfo dataFile) in
D:\WebRoot\PGS\Tool\DBArchiveManager.root\DBArchiveManager\DBArchiveManager\Processor\ImportProcessor\AbstractImportPorcessor.cs:line 5

If I gave the 'PG_TestUser' the 'sysadmin' schema, the code works
Also I have tried that the 'PG_TestUser' do have the select, delete, insert
permision.

AnyOne can help me?

Thank you for your help in advance.

On Sunday, May 11, 2008 5:37 PM
William Vaughn [MVP] wrote:

Don't tell me, the table SVSReportDetail does not exist on the target server.
Don't tell me, the table SVSReportDetail does not exist on the target
server. It must exist and the user must have IO rights.

--
__________________________________________________________________________
William R. Vaughn
President and Founder Beta V Corporation
Author, Mentor, Dad, Grandpa
Microsoft MVP
(425) 556-9205 (Pacific time)
Hitchhiker???s Guide to Visual Studio and SQL Server (7th Edition)
____________________________________________________________________________________________
"George Shui" <(E-Mail Removed)> wrote in message
news:7D7FCDA9-956B-430E-B3A3-(E-Mail Removed)...

On Sunday, May 11, 2008 5:43 PM
GeorgeShu wrote:

Sure. This table do exist.
Sure. This table do exist. And The user can do Select, Insert, Delete on this
table.

Another point is If I gave the user the 'sysadmin', my code can work.

Thanks.

On Monday, May 12, 2008 6:38 AM
William Vaughn [MVP] wrote:

Then it's simply a rights issue.
Then it's simply a rights issue. I would start adding rights until it works
(staring with control).

--
__________________________________________________________________________
William R. Vaughn
President and Founder Beta V Corporation
Author, Mentor, Dad, Grandpa
Microsoft MVP
(425) 556-9205 (Pacific time)
Hitchhiker???s Guide to Visual Studio and SQL Server (7th Edition)
____________________________________________________________________________________________
"George Shui" <(E-Mail Removed)> wrote in message
news:47B38F5D-B49B-4C0D-92A6-(E-Mail Removed)...

EggHeadCafe - Software Developer Portal of Choice
C# .NET Extension Methods 3.0
http://www.eggheadcafe.com/tutorials...n-methods.aspx
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sqlBulkCopy Tony Johansson Microsoft C# .NET 0 30th Sep 2010 09:50 AM
SQLBulkCopy memory issue question SteveB Microsoft ASP .NET 3 10th Nov 2008 01:50 AM
SqlBulkCopy =?Utf-8?B?Sml0ZW5kcmEga3VtYXI=?= Microsoft ADO .NET 1 28th Dec 2006 07:56 PM
SqlBulkCopy mUraliDharan Microsoft ADO .NET 1 20th Dec 2006 02:19 PM
SqlBulkCopy =?Utf-8?B?Um95?= Microsoft C# .NET 0 7th Mar 2006 05:08 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:31 PM.