views:

2190

answers:

2

Hi,

I have two servers, One is application server which has webservice and other server is a DB server,which has SQL server 2005 DB. Webservice is a vb.net app and all the input files will be on app server. When my application calls(through webservice) DB server to execute BULK insert statement with UNC path(of app server) using Windows authentication(Integrated security) then it fails with error -

System.Data.SqlClient.SqlException: Cannot bulk load because the file "\Servername\Foldername\file1.txt" could not be opened. Operating system error code 5(error not found). at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)

I m admin on both servers and webservice is running on my user credentials and also I m SA on SQL DB. SQL server is running on Local system account. I changed it to run on my User account but no luck! However the same statement works when I use SQL authentication in connectionstring.

Can anyone please shed some light on this issue.

Thanks in advance

Sai

A: 

Some ideas for troubleshooting, in random order:

Does the bulk insert work when you run it from Sql Server Management Studio?

Changing the account under which the MSSQLSERVER service operates should help, but did you restart Sql Server after changing the credentials?

Create a command shell that runs under the same user as Sql Server:

runas /noprofile /user:domain\username cmd

And then see if you're allowed to read the network share:

net use \\machine\share
Andomar
Thanks for replying..When i ran the Bulk Insert on SQL mgmt studio(logged in using windows authentication) it worked fine!! After I changed the account under which MSSQLSERVER service runs to domain user(myself as am admin), I restarted the service. But still it did not work..What suprises me is SQL authentication works but window auth is not..!I will try that command shall option and see if that works!!
Yes..am able to accesss the shared folder from DB server using command shell..I think this may be a bug, for Bulk insert statement to not to work using windows auth given a UNC path
Can you show the VB code that does the bulk insert? On rereading, your error message seems to be missing a backslash at the start, "\Servername\Foldername\file1.txt" should start with \\Servername.
Andomar
Yes..my Bulk insert statement is fine..mistakenly I wrote on the post with one"\" missing.
+1  A: 

Your client authenticates with SQL Server, then SQL Server impersonates the client and tries to access the UNC path. That is Delegation and is implicitly forbidden. You must take the explicit steps to enable constrained delegation for the SQL Server service account. See this article explaining the details: http://msdn.microsoft.com/en-us/library/ms998355.aspx The article is shows constrained delegation for an ASP service accessing the back end database, but in your case it would be the SQL Server in the middle accessing the back end UNC share.

Remus Rusanu
Thanks for replying. Yes I think enabling contrained delegation would solve the problem. But its a long shot, for now I have made changes to my application to copy file onto DB server and run bulk insert without any problems.
+1 Super, here's some extra info: "If a user uses a SQL Server login, the security profile of the SQL Server process account is used. In contrast, if a SQL Server user logs on by using Windows Authentication, the user can read only those files that can be accessed by the user account, regardless of the security profile of the SQL Server process." http://msdn.microsoft.com/en-us/library/ms175915.aspx
Andomar