About sqlserver express connections. -
11-16-2006
, 09:05 PM
I download sqlserver 2005 express,setup it with all default params. Then I
create a database "pubs",a table "table1" in "pubs".
After these steps,I try to open the connection with the following csharp
codes:
namespace TCLearn
{
class Program
{
static void Main(string[] args)
{
SqlConnection conn =
new SqlConnection("Server=LocalHost;Integrated
Security=SSPI;Database=pubs");
conn.Open();
}
}
}
Then I got the following exception:
Unhandled Exception: System.Data.SqlClient.SqlException: An error has
occurred while establishing a connection to the server. When connecting to
SQL Server 2
005, this failure may be caused by the fact that under the default settings
SQL Server does not allow remote connections. (provider: Named Pipes
Provider, err
or: 40 - Could not open a connection to SQL Server)
at System.Data.SqlClient.SqlInternalConnection.OnErro r(SqlException
exception, Boolean breakConnection)
at
System.Data.SqlClient.TdsParser.ThrowExceptionAndW arning(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, Boo
lean aliasLookup)
at
System.Data.SqlClient.SqlInternalConnectionTds.Ope nLoginEnlist(SqlConnection
owningObject, SqlConnectionString connectionOptions, String newPassword, Bo
olean redirectedUserInstance)
at
System.Data.SqlClient.SqlInternalConnectionTds..ct or(DbConnectionPoolIdentity
identity, SqlConnectionString connectionOptions, Object providerInfo, Stri
ng newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
at
System.Data.SqlClient.SqlConnectionFactory.CreateC onnection(DbConnectionOptions
options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnecti
on owningConnection)
at
System.Data.ProviderBase.DbConnectionFactory.Creat ePooledConnection(DbConnection
owningConnection, DbConnectionPool pool, DbConnectionOptions options)
at System.Data.ProviderBase.DbConnectionPool.CreateOb ject(DbConnection
owningObject)
at
System.Data.ProviderBase.DbConnectionPool.UserCrea teRequest(DbConnection
owningObject)
at System.Data.ProviderBase.DbConnectionPool.GetConne ction(DbConnection
owningObject)
at
System.Data.ProviderBase.DbConnectionFactory.GetCo nnection(DbConnection
owningConnection)
at
System.Data.ProviderBase.DbConnectionClosed.OpenCo nnection(DbConnection
outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at TCLearn.Program.Main(String[] args) in F:\lr\TCLearn\Program.cs:line
46
What's the problem? Thank you. |