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.
| Type | ConnectionString |
|---|
| Remote using SQL Server authentication | Data Source={HOSTNAME};Database={DATABASE_NAME};user={User};password={password} |
| eg | Data 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
| Type | ConnectionString |
|---|
| remote using windows authentication | Data 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.
| Type | ConnectionString |
|---|
| local database | Data 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.
| Type | ConnectionString |
|---|
| Inside app_data | Data Source=.\SQLEXPRESS;Integrated Security=true;User Instance=true;AttachDbFilename=|DataDirectory|{FILENAME};Database={DATABASE_NAME} |
| eg | Data 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.
| Type | ConnectionString |
|---|
| local file | Data 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):
- {HOSTNAME} – the computer’s name hosting the database, e.g., DatabaseComputer
- {DATABASE_NAME} – e.g., MyOD
- {PATH_TO_FILE} – e.g., c:\Databases\
- {FILENAME} – e.g., MyDatabase.mdf