index > Visual C# General > Error Connecting to Database

Error Connecting to Database

Hi Experts,

When my connection.open() is excuted, i got this error. i am using .NET 2.0 to connect to a database in SQL2005. Kindly Advice! Many thanks!!!!

System.Data.SqlClient.SqlException was unhandled
Message="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)"
Source=".Net SqlClient Data Provider"
ErrorCode=-2146232060
Class=20
LineNumber=0
Number=53
Server=""
State=0
StackTrace:
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 ClientEdition.FrmMainApp.isVisitor(String nric) in C:\Projects\SOS\App\ClientEdition\ClientEdition\FrmMainApp.cs:line 91
at ClientEdition.FrmMainApp.CheckPassport(String nric) in C:\Projects\SOS\App\ClientEdition\ClientEdition\FrmMainApp.cs:line 56
at ClientEdition.FrmMainApp.btnRegister_Click(Object sender, EventArgs e) in C:\Projects\SecurityOperatingSystem\App\ClientEdition\ClientEdition\FrmMainApp.cs:line 27
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.PerformClick()
at System.Windows.Forms.Form.ProcessDialogKey(Keys keyData)
at System.Windows.Forms.TextBoxBase.ProcessDialogKey(Keys keyData)
at System.Windows.Forms.Control.PreProcessMessage(Message& msg)
at System.Windows.Forms.Control.PreProcessControlMessageInternal(Control target, Message& msg)
at System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG& msg)
at System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FPreTranslateMessage(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at ClientEdition.Program.Main() in C:\Projects\SOS\App\ClientEdition\ClientEdition\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
darren.simcc
I can connect to it using SQL Server Management Studio and the SQL Server is stored on the local computer. The SQL Server 2005 is the developer Edition. I am developing on WindowsXP Professional.
darren.simcc

hi darren.simcc

can u please post the connection string which u r using...

and also make sure that u are authorized to use Sql Server

Ankit Nagpal
Two things to note:
  1. Named Pipes does not work when configured as the only clientconnectivity option for ASP.NET running in default circumstances. Havea look at the following article:

    BUG: Named pipes do not work when workerprocess runs under ASPNET account
С?r?s??ρhΞr Sc?δl?ξη

SQL Server 2005 Developer edition disables Remote Connections by default. You can enable it using SQL Server Surface Area Configuration (SSAC) tool. Follow these steps:

1. Launch SSAC from  Programs/Microsoft SQL Server 2005/Configuration Tools/SQL Server Surface Area Configuration

2. Click on "Surface Area Configuration for Services and Connections"

3. On the left hand side treeview, under "Database Engine", select "Remote Connections"

4. Choose "Local and remote connections" on the pane on right side.

5. Press OK.

No try your code again.

Yogesh Prabhu
reply 5

You can use google to search for other answers

 

More Articles

• Why string needs to be passed as ref, even though it is reference...
• Add Security Feactures
• Visual C# installation problems inside Visual Studio 2005
• float datatype gives different result for debug/release build. Bu...
• C# Build Events for VS .NET (2002) Where are they?
• Dataset - 2003 code no longer works with 2005
• System.Net (Soving the .php? link problem !)
• how can i acces a control from another form
• Password?
• JIT optimization
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• dataGridView UserAddedRow event
• Regarding MCPD
• Save Combobox items to file (not .txt)
• sql connection string
• scrollbar in panel
• System.Configuration.ConfigurationManage
• A Better Way to ReUse Sql Objects
• Is this possible??? Word document to SQL
• Setting supportedRuntime property for IE
• how to handled multiple table in windows
• Is Dotfuscator Community Edition with Vi
• Excel export
• print File
• XML newbie
• Books to recommend ?

Hot Articles

• Get windows coin symbol
• how to check the type of an object?
• problem with Smart Navigation in ASP.NET
• Httpwebrequest and Httpweb response and
• Working with database data in textbox co
• Visual C# direct DB update and inserts u
• Database Insert Operation with Windows S
• Show website
• lib files, dll, PInvoke, C#, and visual
• Problem with File.Copy() - Skipping files?
• dll file won't close
• .Parent
• IDispose in detail
• Cannot assign ImageList in Beta 2
• How to use a custom form as a template

Recommend Articles

• How to read JPEG in .NET
• C# using C++ dll throwing exceptions
• database authentication
• Assembly LoadFrom method
• Faking sound from microphone with Direct
• How to know the byte size of a string?
• FileSystemWatcher [File is in user by ot
• Can I add flashing button gif image file
• How to connect to microsoft excel workbo
• Remoting Fundamental
• Thread Safe Access to DateTime
• Reduce exe file size (refractor 3tier to
• converting
• Component class adding a List attribute
• Can anyone solved this problem with Shoc