Re: Accessing an SQL Server database file



Do you mind explaining to me how the connection string written their works?
because i read through it and then tried to use that connection string (of
course with my own db name) but the string is not a valid C# string, i mean
|DataDirectory| as its mentioned in the description is a keyword but its just
hanging there outside the qoutes and of course it didnt compile as it was, i
tried some other combinations, they didnt work either, so can u please either
tell me the correct connection string, or give me an example?

"Nicholas Paldino [.NET/C# MVP]" wrote:

Alex,

Check this link, it will tell you how to create a connection to SQL
Server and attach to a database file:

http://msdn2.microsoft.com/en-us/library/ms165716.aspx

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx

"AlexDP" <AlexDP@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:6BBD0F38-AA0B-4F72-88F1-CB81C739B92F@xxxxxxxxxxxxxxxx
My program has to access an SQL Server DB file that is in the same folder
as
the executable. i dont want to setup a server. i was able to do this on my
own computer, the program would access any sql server db file without it
being attached to the server. When i take it to another system it fails to
run.
All systems have SQL Server Express and SQL Server 2005 installed.

Can someone please direct me through the steps to fix this problem?

There are 2 errors (on different pcs) i get when i try to access the db
one
is:

Error 1

Generating user instances in SQL Server is disabled. Use sp_configure
'user
instances enabled' to generate user instances.


---------------------------
Error 2
---------------------------
System.Data.SqlClient.SqlException: An error has occurred while
establishing
a connection to the server. When connecting to SQL Server 2005, this
failure
may be caused by the fact that under the default settings SQL Server does
not
allow remote connections. (provider: SQL Network Interfaces, error: 26 -
Error Locating Server/Instance Specified)

at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
exception, Boolean breakConnection)

at
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
stateObj)

at System.Data.SqlClient.TdsParser.Connect(Boolean& useFailoverPartner,
Boolean& failoverDemandDone, String host, String failoverPartner, String
protocol, SqlInternalConnectionTds connHandler, Int64 timerExpire, Boolean
encrypt, Boolean trustServerCert, Boolean integratedSecurity,
SqlConnection
owningObject, Boolean aliasLookup)

at
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection
owningObject, SqlConnectionString connectionOptions, String newPassword,
Boolean redirectedUserInstance)

at
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity
identity, SqlConnectionString connectionOptions, Object providerInfo,
String
newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)

at
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions
options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection
owningConnection)

at
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection
owningConnection, DbConnectionPool pool, DbConnectionOptions options)

at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection
owningObject)

at
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection
owningObject)

at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection
owningObject)

at
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection
owningConnection)

at
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection
outerConnection, DbConnectionFactory connectionFactory)

at System.Data.SqlClient.SqlConnection.Open()

at DBManager.SqlDBManager.ConnectToDB() in C:\Documents and
Settings\Alessandro Del Piero\My Documents\Visual Studio
2005\Projects\DBManager\DBManager\SqlDBManager.cs:line 53

at DBModule.Form1.button2_Click(Object sender, EventArgs e) in
G:\DBModule\DBModule\Form1.cs:line 205
---------------------------
OK
---------------------------




.