ado in sql server error 40 [英] ado in sql server error 40

查看:64
本文介绍了ado in sql server error 40的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

System.Data.SqlClient.SqlException未处理

HResult = -2146232060

消息=建立与SQL的连接时发生网络相关或特定于实例的错误服务器。服务器未找到或无法访问。验证实例名称是否正确,以及SQL Server是否配置为允许远程连接。 (提供者:命名管道提供者,错误:40 - 无法打开与SQL Server的连接)

源= .Net SqlClient数据提供者

ErrorCode = -2146232060

Class = 20

LineNumber = 0

Number = 2

Server =

State = 0

StackTrace:

在System.Data.SqlClient.SqlInternalConnection.OnError(SqlException异常,Boolean breakConnection,Action`1 wrapCloseInAction)

在System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj,Boolean callerHasConnectionLock,Boolean asyncClose)

在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)

在System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo,String newPassword,SecureString newSecurePassword,Boolean redirectedUserInstance,SqlConnectionString connectionOptions,SqlCredential credential ,TimeoutTimer超时)

在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 Syste m.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions选项,DbConnectionPoolKey poolKey,Object poolGroupProviderInfo,DbConnectionPool池,DbConnection owningConnection,DbConnectionOptions userOptions)

在System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool池, DbConnectionOptions选项,DbConnectionPoolKey poolKey,DbConnectionOptions userOptions)

在System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnectionOptions userOptions)

在System.Data.ProviderBase.DbConnectionPool.UserCreateRequest( DbConnectionOptions userOptions)

在System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,UInt32 waitForMultipleObjectsTimeout,Boolean allowCreate,Boolean onlyOneCheckConnection,DbConnectionOptions userOptions,DbConnectionInternal&connection)

at System .Data.ProviderBase.DbConnectionPool.TryGetConnection (DbConnection owningObject,TaskCompletionSource`1 retry,DbConnectionOptions userOptions,DbConnectionInternal&connection)

在System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection,TaskCompletionSource`1 retry,DbConnectionOptions userOptions,DbConnectionInternal&connection)

在System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection,DbConnectionFactory connectionFactory,TaskCompletionSource`1 retry,DbConnectionOptions userOptions)

at System.Data.SqlClient.SqlConnection.TryOpen( TaskCompletionSource`1重试)

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

at h22.Form1.Form1_Load(Object sender,EventArgs e)in c:\\ \\ Users\hend \Documents\Visual Studio 2012 \Projects\ h22\h22\Form1.cs:第26行

at System.Windows.Forms.Form.OnLoad(EventArgs e)在System.Windo上
ws.Forms.Form.OnCreateControl()

在System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)

在System.Windows.Forms.Control.CreateControl( )

在System.Windows.Forms.Control.WmShowWindow(Message&m)

在System.Windows.Forms.Control.WndProc(Message&m)

在System.Windows.Forms.ScrollableControl.WndProc(Message&m)

在System.Windows.Forms.ContainerControl.WndProc(Message&m)

在System。 Windows.Forms.Form.WmShowWindow(Message&m)

在System.Windows.Forms.Form.WndProc(Message&m)

在System.Windows.Forms.Control。 ControlNativeWindow.OnMessage(Message&m)

在System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&m)

在System.Windows.Forms.NativeWindow.DebuggableCallback( IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)

在System.Windows.Forms.SafeNativeMethods.S howWindow(HandleRef hWnd,Int32 nCmdShow)

在System.Windows.Forms.Control.SetVisibleCore(布尔值)

在System.Windows.Forms.Form.SetVisibleCore(布尔值在System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason,ApplicationContext context)中System.Windows.Forms.Control.set_Visible(布尔值)

$)


在System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason,ApplicationContext context)

在System.Windows.Forms.Application.Run(Form mainForm)

at h22.Program.Main()in c:\ Users \ hend \Documents\Visual Studio 2012 \Projects\h22\h22\Program.cs:第19行

在System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly,String [] args)

在System.AppDomain.ExecuteAssembly(String assemblyFile,Evidence assemblySecurity,String [] args)

at System.Threading.ThreadHelper.ThreadStart_Context(对象状态)中的$。
。在System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext)中的
.Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

,ContextCallback回调,Object state,Boolean preserveSyncCtx)

在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,Object state,Boolean preserveSyncCtx)

在System。 Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态)

at System.Threading.ThreadHelper.ThreadStart()

InnerException:System.ComponentModel.Win32Exception

HResult = -2147467259

消息=系统找不到指定的文件

ErrorCode = -2147467259

NativeErrorCode = 2

InnerException:

解决方案

基本上,当您无法连接到SQL Server时,问题可能是:

1)网络问题,

2)SQL Server配置问题。

3)防火墙问题,

4)客户端驱动程序问题,

5)应用程序配置问题。

6)身份验证和登录问题。

检查这些

< a href =http://blogs.msdn.com/b/sql_protocols/archive/2008/04/30/steps-to-troubleshoot-connectivity-issues.aspx>解决SQL连接问题的步骤 [ ^ ]

SQL Server 2005连接问题疑难解答 - 第一部分 [ ^ ]

解决SQL Server 2005中的连接问题 - 第二部分 [ ^ ]

解决SQL Server 2005中的连接问题 - 第III部分 [< a href =http://blogs.msdn.com/b/sql_protocols/archive/2005/12/22/506607.aspxtarget =_ blanktitle =New Window> ^ ]

System.Data.SqlClient.SqlException was unhandled
HResult=-2146232060
Message=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: 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=2
Server=""
State=0
StackTrace:
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)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at h22.Form1.Form1_Load(Object sender, EventArgs e) in c:\Users\hend\Documents\Visual Studio 2012\Projects\h22\h22\Form1.cs:line 26
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
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 h22.Program.Main() in c:\Users\hend\Documents\Visual Studio 2012\Projects\h22\h22\Program.cs:line 19
at System.AppDomain._nExecuteAssembly(RuntimeAssembly 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.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.ComponentModel.Win32Exception
HResult=-2147467259
Message=The system cannot find the file specified
ErrorCode=-2147467259
NativeErrorCode=2
InnerException:

解决方案

Basically, when you failed to connect to your SQL Server, the issue could be:
1) Network issue,
2) SQL Server configuration issue.
3) Firewall issue,
4) Client driver issue,
5) Application configuration issue.
6) Authentication and logon issue.

Check these
Steps to troubleshoot SQL connectivity issues[^]
SQL Server 2005 Connectivity Issue Troubleshoot - Part I[^]
Troubleshoot Connectivity Issue in SQL Server 2005 - Part II[^]
Troubleshoot Connectivity Issue in SQL Server 2005 - Part III[^]


这篇关于ado in sql server error 40的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆