K
kanepart2
I am making a simple program to use display SQL data using C#
SqlConnection myConnection = new
SqlConnection(@"Trusted_Connection=yes;database=*****database
name*****;connection timeout=30");
try
{
myConnection.Open();
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
above is the code snippet where I run into problems..
myConnection.Open times out and the exception gets thrown. I have no
clue why!
the following is the content of the exception
-----------------------------------------------------------------------------------------------------------------------------
"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: Named Pipes Provider, error: 40 - Could not open a
connection to SQL Server)\r\n at
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
exception, Boolean breakConnection)\r\n at
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
stateObj)\r\n 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)\r\n at
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection
owningObject, SqlConnectionString connectionOpt
ions, String newPassword, Boolean redirectedUserInstance)\r\n at
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity
identity, SqlConnectionString connectionOptions, Object providerInfo,
String newPassword, SqlConnection owningObject, Boolean
redirectedUserInstance)\r\n at
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions
options, Object poolGroupProviderInfo, DbConnectionPool pool,
DbConnection owningConnection)\r\n at
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection
owningConnection, DbConnectionPool pool, DbConnectionOptions options)\r
\n at
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection
owningObject)\r\n at
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection
owningObject)\r\n at
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection
owningObject)\r\n at
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection
owningConnection)\r\n at S
ystem.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection
outerConnection, DbConnectionFactory connectionFactory)\r\n at
System.Data.SqlClient.SqlConnection.Open()\r\n at
SqlSample.Program.Main(String[] args) in
SqlConnection myConnection = new
SqlConnection(@"Trusted_Connection=yes;database=*****database
name*****;connection timeout=30");
try
{
myConnection.Open();
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
above is the code snippet where I run into problems..
myConnection.Open times out and the exception gets thrown. I have no
clue why!
the following is the content of the exception
-----------------------------------------------------------------------------------------------------------------------------
"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: Named Pipes Provider, error: 40 - Could not open a
connection to SQL Server)\r\n at
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
exception, Boolean breakConnection)\r\n at
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
stateObj)\r\n 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)\r\n at
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection
owningObject, SqlConnectionString connectionOpt
ions, String newPassword, Boolean redirectedUserInstance)\r\n at
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity
identity, SqlConnectionString connectionOptions, Object providerInfo,
String newPassword, SqlConnection owningObject, Boolean
redirectedUserInstance)\r\n at
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions
options, Object poolGroupProviderInfo, DbConnectionPool pool,
DbConnection owningConnection)\r\n at
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection
owningConnection, DbConnectionPool pool, DbConnectionOptions options)\r
\n at
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection
owningObject)\r\n at
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection
owningObject)\r\n at
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection
owningObject)\r\n at
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection
owningConnection)\r\n at S
ystem.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection
outerConnection, DbConnectionFactory connectionFactory)\r\n at
System.Data.SqlClient.SqlConnection.Open()\r\n at
SqlSample.Program.Main(String[] args) in