Writing a connection string to access a remote SQL Server database

33,290

Solution 1

You are encountering the error because you are using "integrated security=true" to connect. Use this website to construct your connection string. http://www.developerfusion.com/tools/sql-connection-string/

I used the website to generate this connection string using your inputs:

Data Source=abcs.efgh.ed-1.eee.sss.com,1433;Initial Catalog=mydb;Integrated Security=False;User ID=a;Password=a

Solution 2

Put Integrated security =false. in connection string

When false, User ID and Password are specified in the connection. When true, the current Windows account credentials are used for authentication. Recognized values are true, false, yes, no, and sspi (strongly recommended), which is equivalent to true. If User ID and Password are specified and Integrated Security is set to true, the User ID and Password will be ignored and Integrated Security will be used. SqlCredential is a more secure way to specify credentials for a connection that uses SQL Server Authentication (Integrated Security=false).

More at Here

Share:
33,290
Sharon Watinsan
Author by

Sharon Watinsan

Updated on September 15, 2020

Comments

  • Sharon Watinsan
    Sharon Watinsan over 3 years

    My database is hosted on a remote server. I need to write the connection string which I have to include in the web.config file.

    server name -- abcs.efgh.ed-1.eee.sss.com,1433 (it also contains a port as well)
    username -- a
    password -- a
    db name -- mydb
    

    I know how to connect to a local database and I use to refer to connectionstring.com for reference but, connecting to a remote database is a problem to me. Help please

    UPDATE:

    <connectionStrings>                                 
      <add name="DefaultConnection" providerName="System.Data.SqlClient" 
           connectionString="abcs.efgh.ed-1.eee.sss.com,1433;Integrated Security=True;User ID=a;Password=a" />
    </connectionStrings>
    

    Exception I get is :

    Login failed. The login is from an untrusted domain and cannot be used with Windows authentication.

    Actually, it's not Windows authentication that I want to use. It's SQL Server authentication which I want.