0

I am trying to get data from SQL SERVER and display in SharePoint 2013 web part. I wrote following code to connect SQL SERVER. But it gives an error "login failed for user 'nt authority iusr" when connecting. But same code work for C#. Is the issue is something related to SharePoint?

 string connetionString = "Data Source=WIN-SERVER2012;Initial Catalog=ExternalDBTest;User ID=Administrator; Password=password; Trusted_Connection=True";
 using (SqlConnection cn = new SqlConnection(connetionString))
            {
                  cn.Open();

            }

1 Answer 1

1

Try to remove Trusted_Connection=True from your connection string when you try to use SQL Authentication.

Trusted_Connection=True is only used with Windows Authentication and in your case, this user User ID=Administrator will be ignored , so the connection string tries to connect to your database with this user nt authority iusr that does not have access to ExternalDBTest

2
  • It's not working for me. I get an error login failed for the user. Commented Oct 7, 2016 at 8:38
  • 1
    Make sure that the provided user has elevated privileges to your database and also don't add Trusted_Connection=True, or try to use sa user and check , I am pretty sure the issue related Trusted_Connection=True and current user permission or password Commented Oct 7, 2016 at 11:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.