SQL Server Connection Strings

SQL Server Database Connection String

The connection string defines the connection to your database. A good reference on connection strings is ConnectionStrings.com

The Web services run as Network Service by default.

SQL Server Full Version Examples

Recommended method is to have an SQL server account, which has Read-only access to the database. This applies to local or remote servers. While secure and simple, this has some security issues that some system administrators may not desire.
TypeConnectionString
Remote using SQL Server authenticationData Source={HOSTNAME};Database={DATABASE_NAME};user={User};password={password}
egData Source=HIS.EXAMPLE.COM;Database=LittleBear;user=webservice;password=webservice

Example where the database server exists.
In this case, you will need to grant access to Network Service to connect to the database. This is for a local database server, or for a remote server that shares the same user accounts. This is the most seucre method
TypeConnectionString
remote using windows authenticationData Source={HOSTNAME};Integrated Security=true;Database={DATABASE_NAME}
eg ||Data Source=HIS.EXAMPLE.COM;Integrated Security=true;Database=LittleBear

SQL Server SQLExpress Examples

SQL Express is a low maintenance version of SQL server. It is limited to 2 gigabytes of space per database.

SQL Express Example:
The database is installed in the local SQLEXPRESS, using the SQL Manager Express. In this case, you will need to grant access to Network Service to connect to the database.
TypeConnectionString
local databaseData Source=.\SQLEXPRESS;Integrated Security=true;Database={DATABASE_NAME}
eg ||Data Source=.\SQLEXPRESS;Integrated Security=true;Database=OD

This example is a file. You will not be able to upload data to a database, and run a web service at the same time.
TypeConnectionString
Inside app_dataData Source=.\SQLEXPRESS;Integrated Security=true;User Instance=true;AttachDbFilename=|DataDirectory|{FILENAME};Database={DATABASE_NAME}
egData Source=.\SQLEXPRESS;Integrated Security=true;User Instance=true;AttachDbFilename=|DataDirectory|OD.mdf;Database=OD

File inside of the ASP.NET applicaiton.
For ASP.NET, you can have a app_data directory, which will store data for your asp.net applications. You will not be able to upload data to a database, and run a web service at the same time.
TypeConnectionString
local fileData Source=.\SQLEXPRESS;Integrated Security=true;User Instance=true;AttachDbFilename={PATH_TO_FILE}{FILENAME};Database={DATABASE_NAME}
eg ||Data Source=.\SQLEXPRESS;Integrated Security=true;User Instance=true;AttachDbFilename=P:/databases/od.mdf;Database=od



Connection to a Microsoft Access 2007 Database

(Note: This is untested)

provider=Microsoft.ACE.OLEDB.12.0;Data Source={PATH_TO_FILE}\{FILENAME};Persist Security Info=False



Note: In the connection string, replace the items in brackets with your actual items (do not include the brackets):