连接到没有SQL Server的数据库mdf [英] Connecting to Database mdf without SQL Server

查看:277
本文介绍了连接到没有SQL Server的数据库mdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

im使用带有LOCAL数据库(mdf)的.net webservice。
这个网站工作正常,直到我把所有的文件移动到另一台计算机,并创建
一个新的应用程序在iis。
所有的方法在这个webservice工作很好,只是需要连接和查询数据库的方法,我得到以下错误:

  System.Data.SqlClient.SqlException:与SQL Server建立连接时发生网络相关或实例特定的错误。找不到服务器或无法访问。验证实例名称是否正确并且SQL Server配置为允许远程连接。 (提供程序:SQL网络接口,错误:26  - 指定服务器/实例错误)
在System.Data.SqlClient.SqlInternalConnection.OnError(SqlException异常,布尔breakConnection)
在System.Data.SqlClient。 TdsParser.ThrowExceptionAndWarning()
在System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo,SqlInternalConnectionTds connHandler,Boolean ignoreSniOpenTimeout,Int64 timerExpire,Boolean encrypt,Boolean trustServerCert,Boolean integratedSecurity)
在System.Data。 SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo,String newPassword,Boolean ignoreSniOpenTimeout,TimeoutTimer timeout,SqlConnection owningObject)
在System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo,String newPassword,Boolean redirectedUserInstance,SqlConnection owningObject,SqlConnectionString connectionOptions ,TimeoutTimer timeout)
在System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject,TimeoutTimer timeout,SqlConnectionString connectionOptions,String newPassword,Boolean redirectedUserInstance)
在System.Data.SqlClient.SqlInternalConnectionTds..ctor DbConnectionPoolIdentity标识,SqlConnectionString connectionOptions,Object providerInfo,String newPassword,SqlConnection owningObject,Boolean redirectedUserInstance)
在System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions选项,对象poolGroupProviderInfo,DbConnectionPool池,DbConnection拥有连接)
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection,DbConnectionPool pool,DbConnectionOptions选项)
在System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
在System.Data.ProviderBase.DbConnectionPool。 UserCreateRequest(DbConnection owningObject)
在System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
在System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection拥有连接)
在System.Data。 ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection,DbConnectionFactory connectionFactory)
在System.Data.SqlClient.SqlConnection.Open()
在System.Data.Linq.SqlClient.SqlConnectionManager.UseConnection(IConnectionUser用户)
at System.Data.Linq.SqlClient.SqlProvider.get_IsSqlCe()
在System.Data.Linq.SqlClient.SqlProvider.InitializeProviderMode()
在System.Data.Linq.SqlClient.SqlProvider.System .Data.Linq.Provider.IProvider.Execute(Expression query)
在System.Data.Linq.Table`1.System.Linq.IQueryProvider.Execute [TResult](表达式表达式)
在System。 Linq.Queryable.ElementAt [TSource](IQueryable`1 source,Int32 index)

config连接字符串几次,没有防火墙保护。



感谢...

解决方案

我建议进行几项基础设施检查,有时候比仅关注代码更好:


  1. SQL Server具有正确的LAN连接

  2. 从托管您的Web服务的服务器到承载SQL Server的服务器执行ping操作

  3. 使用MAnagement Studio从不同的服务器查询数据库对象(可能是网络管理员无意中阻止了重要端口)

连接字符串,有时分号可以毁掉整个事物。



EDIT

连接字符串

 < add name =gatewayConnectionString
connectionString = = .\SQLEXPRESS; AttachDbFilename = c:\Projects\p\file.mdf;集成安全性= True; Connect Timeout = 30;用户实例= True
providerName =System.Data.SqlClient />

希望它有帮助,


im using .net webservice with a LOCAL database (mdf). this all website worked fine until i moved all the files to another computer as is and created a new application on iis. all the methods on this webservice working just fine, just the methods that need to connect and query the database i get the following error:

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)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
   at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity)
   at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject)
   at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout)
   at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, 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 System.Data.Linq.SqlClient.SqlConnectionManager.UseConnection(IConnectionUser user)
   at System.Data.Linq.SqlClient.SqlProvider.get_IsSqlCe()
   at System.Data.Linq.SqlClient.SqlProvider.InitializeProviderMode()
   at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
   at System.Data.Linq.Table`1.System.Linq.IQueryProvider.Execute[TResult](Expression expression)
   at System.Linq.Queryable.ElementAt[TSource](IQueryable`1 source, Int32 index)

ive change the web config connection string couple of times and there is no firewall protection.

thanks...

解决方案

I would suggest a couple of infrastructure checks, sometimes is better than just focusing on the code:

  1. Ensure your SQL server has proper LAN connection
  2. Make a ping from the server hosting your web service to the the server hosting your SQL Server
  3. Use the MAnagement Studio to query for database objects from a different server (may be possible that a network administrator blocked important ports inadvertently)

If possible check twice your connection string, sometimes a semicolon can ruin the whole thing.

EDIT

Connection String

<add name="gatewayConnectionString" 
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=c:\Projects\p\file.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True" 
providerName="System.Data.SqlClient"/> 

Hope it helps,

这篇关于连接到没有SQL Server的数据库mdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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