0

I am installing an open source tool, and when defining the database setting I need to specify the database connection string. They provide an example for a connection string for SQL Server Express as follow:

Database=roadkill;Server=.\SQLEXPRESS;uid=username;pwd=password;

But since I am using SQL Server 2008 R2 and not SQL Server Express, how I can define the connection string for my SQL Server 2008 R2 in the same way?

Thanks

Edit

I tried the following connection string :-

Data Source=.\SQLExpress;Integrated Security=true; AttachDbFilename=C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\roadkill.mdf

but I got the following exception :-

System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover)
   at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover)
   at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)
   at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
2

2 Answers 2

2

The connection string format for SQL Server and SQL Server Express is exactly the same. In both cases, the Server or Data Source value must be the server and instance name. The ".\SQLEXPRESS" simply means an instance named "SQLEXPRESS" on the local machine. It's convention that that instance name be used for SQL Server Express but it's not required. You could use a different name or you could use that name for a full SQL Server instance, although it would misleading. It's simply an identifying label. In all cases, use "ServerName\InstanceName" for a named instance and just "ServerName" for a default instance. You can use "." or "(local)" to refer to the local machine.

2
  • That error message suggests that there is no instance named "SQLEXPRESS" on the local machine. May 16, 2014 at 15:08
  • By the way, why are you trying to attach a file that appears to be in a location that suggests that it is, or should be, already permanently attached? May 16, 2014 at 15:09
0

No difference between this two version of sqlserver. Only difference comes in sqlexpress for server parameter written as ".SQLEXPRESS" or say (LOCAL) for both case.

database=".Sqlexpress"
or database="(local)"

Your Answer

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