Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing a connection string to access a remote SQL Server database

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.

like image 810
Sharon Watinsan Avatar asked May 23 '13 03:05

Sharon Watinsan


2 Answers

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
like image 175
Jay Jay Jay Avatar answered Sep 19 '22 13:09

Jay Jay Jay


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

like image 24
Rajeev Kumar Avatar answered Sep 20 '22 13:09

Rajeev Kumar