sql server bulk copy login error from web application

i have a new c# web application in .net 4 hosted on iis7. this is an intranet application.  i have a function that builds a DataTable then does a bulkcopy.write(datatable) to sql server 2008 table.  

My connection string specifies a userid and password on sql server (sql authentication).  I have given this user id sqladmin and bulkadmin rights, have added it to the users for the target table to bulk copy into, but still get a "login failed for 'dbAdmin' " error.  

please help!
dhenderson12Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Johny BravoCommented:
Are you able to connect to database for other functionalities.
Is this is the only functionality where the connection error is produced?

 SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["Target"].ConnectionString);
            try
            {
                myConnection.Open();
                SqlBulkCopy myCommand = new SqlBulkCopy(myConnection);

                myCommand.DestinationTableName = "dbo.Products";
                myCommand.WriteToServer(dt);
                myCommand.Close();
            }
            catch (Exception err)
            {                
                throw err;
            }
            finally
            {
                myConnection.Close();
            }
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dhenderson12Author Commented:
in fact, that's is what I'm doing.  but it generates the "login failed for 'dbAdmin' " error.
running stored procs, updating tables, all work fine using this user.
0
dejaanbuCommented:
the pbm should be in connectionstring...

check if you have "integrated security" part in your connectionstring. if so, try remove the "integrated security" part from your db connectionstring.

if not, post your code...
0
Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

dhenderson12Author Commented:
yes, I have.  A little history:  we were using integrated security in the connection strings so that only users that belonged to a specific Active Directory group could connect to both the web app AND sql server.  Due to problems with pass-through security on IIS7 I had to remove the integrated security in the connection string and replace with a specific sql user and password.

Since I have done that, I connect to sql server (2008 r2) and run the stored procs, queries, etc. that I need to, but I cannot get the bulk copy to work, and that's one of the most important pieces of this application.  Here's the connection string:

    <add name="DBConnection" 
             connectionString="Data Source=<sql server>;Initial Catalog=myDB;
                 User ID=myDBAdmin;Password=myDBAdminPWD;"
             providerName="System.Data.SqlClient" />

Open in new window

0
Johny BravoCommented:
Can you post the code you are using?

Try setting ,

EXEC sp_addrolemember ‘db_owner’, ‘YourAdmin’

Also check,
http://blogs.msdn.com/b/dataaccesstechnologies/archive/2012/03/22/10082977.aspx
0
dhenderson12Author Commented:
giving db_owner rights on the database didn't solve the problem.  I will try suggestions in the link tomorrow.  thanks for the suggestions.
0
dhenderson12Author Commented:
yeah, the information in the link didn't really provide an answer, either.
0
dhenderson12Author Commented:
I found the problem.
The code to call the bulk copy was using the 2nd override of SQLBulkCopy object:
SqlBulkCopy myCommand = new SqlBulkCopy(myConnection.ConnectionString)

simply using the connection object itself worked, which is what johnny_bravo1 used in his example.

thanks to all who helped, but jb1 gets the points because he posted the answer first and I just didn't see the difference between his answer and my code.
0
dhenderson12Author Commented:
thanks, man.  sorry i didn't see the difference earlier ... i could have saved 2 days of hassle.
0
Johny BravoCommented:
Glad your problem is solved :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.