GVKun编程网logo

asp.net – 与SQL Server建立连接时出现网络相关或实例特定错误[已关闭]

13

在本文中,我们将带你了解asp.net–与SQLServer建立连接时出现网络相关或实例特定错误[已关闭]在这篇文章中,同时我们还将给您一些技巧,以帮助您实现更有效的.net–建立与SQLServer

在本文中,我们将带你了解asp.net – 与SQL Server建立连接时出现网络相关或实例特定错误[已关闭]在这篇文章中,同时我们还将给您一些技巧,以帮助您实现更有效的.net – 建立与SQL Server的连接时发生错误、asp.net – 无法打开与SQL Server的连接、asp.net – 此版本的SQL Server不支持用户实例登录标志 连接将关闭、ASP.NET,MySQL与SQL Server中的数据库连接

本文目录一览:

asp.net – 与SQL Server建立连接时出现网络相关或实例特定错误[已关闭]

asp.net – 与SQL Server建立连接时出现网络相关或实例特定错误[已关闭]

我在somee.com上部署了我的asp.net Web应用程序,每当我登录到这个网站(ipc.somee.com),它给我一个网络相关的错误,如:
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: sql Network Interfaces,error: 26 - Error Locating Server/Instance Specified)

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.sqlClient.sqlException: 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: sql Network Interfaces,error: 26 - Error Locating Server/Instance Specified)

Source Error: 

An unhandled exception was generated during the execution of the current web request. information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace: 


[sqlException (0x80131904): 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: sql Network Interfaces,error: 26 - Error Locating Server/Instance Specified)]
   System.Data.sqlClient.sqlInternalConnection.OnError(sqlException exception,Boolean breakConnection,Action`1 wrapCloseInAction) +5296071
   System.Data.sqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj,Boolean callerHasConnectionLock,Boolean asyncclose) +558
   System.Data.sqlClient.TdsParser.Connect(ServerInfo serverInfo,sqlInternalConnectionTds connHandler,Boolean ignoreSniOpenTimeout,Int64 timerExpire,Boolean encrypt,Boolean trustServerCert,Boolean integratedSecurity,Boolean withFailover) +5308555
   System.Data.sqlClient.sqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo,String newPassword,securestring newSecurePassword,TimeoutTimer timeout,Boolean withFailover) +145
   System.Data.sqlClient.sqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo,Boolean redirectedUserInstance,sqlConnectionString connectionoptions,sqlCredential credential,TimeoutTimer timeout) +920
   System.Data.sqlClient.sqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout,Boolean redirectedUserInstance) +307
   System.Data.sqlClient.sqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity,Object providerInfo,sqlConnectionString userConnectionoptions) +434
   System.Data.sqlClient.sqlConnectionFactory.CreateConnection(DbConnectionoptions options,DbConnectionPoolKey poolKey,Object poolGroupProviderInfo,DbConnectionPool pool,DbConnection owningConnection,DbConnectionoptions userOptions) +5311099
   System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool,DbConnectionoptions options,DbConnectionoptions userOptions) +37
   System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnectionoptions userOptions) +558
   System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnectionoptions userOptions) +67
   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,UInt32 waitForMultipleObjectsTimeout,Boolean allowCreate,Boolean onlyOneCheckConnection,DbConnectionoptions userOptions,DbConnectionInternal& connection) +1052
   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,taskcompletionsource`1 retry,DbConnectionInternal& connection) +78
   System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection,DbConnectionInternal& connection) +167
   System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection,DbConnectionFactory connectionFactory,DbConnectionoptions userOptions) +143
   System.Data.sqlClient.sqlConnection.TryOpen(taskcompletionsource`1 retry) +83
   System.Data.sqlClient.sqlConnection.open() +96
   Default.log(Object sender,EventArgs e) in c:\users\sreekanth\documents\visual studio 2010\Projects\IPCWebApp\IPCWebApp\Default.aspx.cs:43
   System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +115
   System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +124
   System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl,String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterasyncPoint) +1724

解决方法

当您的应用程序没有足够的权限访问数据库时,sql Server将触发此错误。这个错误有几个原因。要解决此错误,您应该遵循以下说明。

>尝试使用管理工作室从服务器连接Sql Server。如果使用Windows身份验证连接Sql Server,则将应用程序池标识设置为服务器管理员。
>如果您使用sql server身份验证,那么请检查web应用程序的web.config中的连接字符串,并设置允许您登录的sql server的用户名和密码。
>如果您的数据库在其他服务器(访问远程数据库)中,则首先启用sql server的远程访问,从sql server management studio启动sql server属性,并启用TCP / IP表单sql server配置管理器。
>在完成所有这些内容后,您仍然无法访问数据库,然后检查要尝试访问数据库的服务器窗体的防火墙,并在防火墙中添加一个规则以启用sql server的端口(默认情况下,sql server使用1433,to检查sql server的端口,需要检查sql server配置管理器的网络协议TCP / IP端口)。
>如果您的sql server在命名实例上运行,则需要使用sql serer名称写入端口号,例如117.312.21.21/nameofsqlserver1433。
>如果您正在使用像amazon aws或microsoft azure这样的云托管服务器或实例将运行在云端防火墙后面,因此如果您有命名实例的sql server的默认实例或特定端口,则需要在云端防火墙中启用1433端口。
>如果您使用的是亚马逊RDS或sql azure,则需要从该实例的安全组启用端口。
>如果您通过sql server身份验证模式访问sql server,请确保启用了“sql Server和Windows身份验证模式”sql server instance属性。

>在对属性进行任何更改后重新启动sql server实例,因为某些更改将需要重新启动。

如果您进一步面对任何困难,那么您需要提供有关您的网站和sql服务器的更多信息。

.net – 建立与SQL Server的连接时发生错误

.net – 建立与SQL Server的连接时发生错误

如果我有这样的web.config中的我的连接字符串(添加的行提要更好的可读性):
<add 
name="conn" 
connectionString="Data Source=(localdb)\v11.0; Initial 
    Catalog=MyDB; Integrated Security=True; MultipleActiveResultSets=True; 
    AttachDbFilename=D:\Products.mdf" 
providerName="System.Data.sqlClient"/>

连接工作,我可以连接到数据库资源管理器中的数据库.

当我在代码中指定connectionstring或使用ConfigurationManager获取它不起作用:

sqlCommand command = new sqlCommand();
    command.CommandText = "select ...";
    command.CommandType = CommandType.Text;
    sqlConnection cn = new sqlConnection("Data Source=(localdb)\\v11.0;"+
        "Initial Catalog=MyDB; Integrated Security=True; "+
        "MultipleActiveResultSets=True; AttachDbFilename=D:\\Products.mdf");
    command.Connection = cn;
    cn.open();
    DataTable dataTable = new DataTable();
    sqlDataReader reader;
    reader = command.ExecuteReader();
    dataTable.Load(reader);
    cn.Close();

从web.config获取连接字符串给出相同的错误:

sqlConnection cn = new sqlConnection(ConfigurationManager.ConnectionStrings
 ["conn"].ConnectionString;

我得到的错误是“System.ComponentModel.Win32Exception:找不到网络路径”

在痕迹中说:

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

我需要一些帮助解决这个问题,一直在努力解决这个问题,几个小时,任何在线建议是我应该检查网络设置(不适用,因为它连接到本地实例的sql server express).服务器名称(相同的字符串在VS Express中工作,但不在运行代码中).

可能是认证问题吗?如果是这样,为什么不提供信息错误?

感谢您阅读我的帖子,希望您能帮助我.

更新:

我尝试了以下几点:

给予该组所有对mdf和ldf文件的完全许可

在Web下的项目属性中,我尝试在VS开发服务器和本地IIS Web服务器(IIS Express)下运行项目,

没有运气,当将代码复制到使用“ASP.NET空Web应用程序”创建的项目时,仍然无法连接到连接完美的位置

解决方法

您正确地转义了数据库文件名,而不是数据源,因此它尝试连接到名为“(localdb)11.0”的数据源,这很可能不存在.

尝试像这样正常地转义它:

sqlConnection cn = new sqlConnection("Data Source=(localdb)\\v11.0;"+
"Initial Catalog=MyDB; Integrated Security=True; "+
"MultipleActiveResultSets=True; AttachDbFilename=D:\\Products.mdf");

asp.net – 无法打开与SQL Server的连接

asp.net – 无法打开与SQL Server的连接

我在连接数据库服务器时遇到问题.数据库服务器不是本地的,我通过其IP地址连接.

它在我的开发机器上运行良好.将网站发布到我的服务器后,它无法连接到我的数据库服务器.

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)

为什么我的发布服务器无法连接到数据库服务器,而它可以通过开发机器正常工作?

解决方法

我经常遇到这个问题.主要是因为两个问题.

>打开sql Server配置管理器.

>检查sql Server网络配置是否支持TCP / IP,如果已禁用,则启用它.
例如sqlServer 2005网络配置,sqlEXPRESS的协议

>打开sql Server Management Studio

>单击sql Server属性(右键单击服务器名称和
选择属性).
>之后,选择“安全性”页面并将检查切换到“sql Server和Windows身份验证模式”.

就这样.

asp.net – 此版本的SQL Server不支持用户实例登录标志 连接将关闭

asp.net – 此版本的SQL Server不支持用户实例登录标志 连接将关闭

嗨,我正在使用sql server fulll版本。

任何想法我该如何解决这个问题,我在网上搜索,但没有找到任何有用的答案。

谢谢

解决方法

sql Server 2005(完整版)不支持连接字符串中的“用户实例”(从代码自动创建数据库)指令。它的特点是sql server express版本。

另外如果你的连接字符串有用户实例属性,那么尝试删除“用户实例=真”;

ASP.NET,MySQL与SQL Server中的数据库连接

ASP.NET,MySQL与SQL Server中的数据库连接

我正在使用 MySQL在我正在进行的ASP.NET项目中,我做了一些测试来测试MysqL .NET提供程序的性能,但遗憾的是我对结果并不满意.

只打开连接的一个非常简单的循环在sql Server中快了10倍:

// MysqL

const string CONNECTION_STRING = 
"server=localhost;database=testdb;user id=root;password=mypassword;max pool size=250;";
for (int i = 0; i < 5000; i++)
{
  using (MysqLConnection con = new MysqLConnection(CONNECTION_STRING))
  {
    con.open();
  }
}

// sql Server

const string CONNECTION_STRING = "Data Source=localhost;Initial Catalog=testdb;Integrated Security=True;max pool size=250;";
for (int i = 0; i < 5000; i++)
{
  using (sqlConnection con = new sqlConnection(CONNECTION_STRING))
  {
    con.open();
  }
}

sql Server在其他任何方面都要快得多(选择,更新,插入……等).我做错了吗?我应该改变哪些服务器变量?

更多信息:
– 我在Windows上运行MysqL(5.0.51a-community-nt)
– 测试中使用了sql Server 2005
– 规格:Windows XP SP2,cpu Intel 1.6GHz双核,1024 MB RAM

这是MysqL的配置:

[client]
port        = 3306
socket      = /tmp/MysqL.sock

[MysqLd]
port        = 3306
socket      = /tmp/MysqL.sock
skip-locking
key_buffer = 384M
max_allowed_packet = 1M
table_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M
thread_concurrency = 8

server-id   = 1

[MysqLdump]
quick
max_allowed_packet = 16M

[MysqL]
no-auto-rehash

[isamchk]
key_buffer = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M

[myisamchk]
key_buffer = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M

[MysqLhotcopy]
interactive-timeout

谢谢你的任何建议……

解决方法

默认情况下,sql Server使用连接池:关闭时,使用完全相同的连接字符串打开的每个连接都将返回到池中.从池中返回连接比从头创建连接更有效.我假设默认情况下MysqL不提供连接池

关于asp.net – 与SQL Server建立连接时出现网络相关或实例特定错误[已关闭]的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于.net – 建立与SQL Server的连接时发生错误、asp.net – 无法打开与SQL Server的连接、asp.net – 此版本的SQL Server不支持用户实例登录标志 连接将关闭、ASP.NET,MySQL与SQL Server中的数据库连接的相关信息,请在本站寻找。

本文标签: