首页 新闻 会员 周边 捐助

asp.net core 部署问题

0
悬赏园豆:10 [已解决问题] 解决于 2017-10-13 18:09

我在本机安装了sqlserver 2016express,然后在本机开发asp.net core应用,该应用连接数据库进行存储。我又在本机安装了虚拟机,并在虚拟机上安装了Ubuntu系统,然后dotnet publish发布了我的应用,随后把发布的文件夹上传到本机的Ubuntu系统上,我发现数据库连接不上了,如何处理??请求大家的帮助,谢谢

问题补充:

数据库连接使用的是ef2.0

wall-ee的主页 wall-ee | 初学一级 | 园豆:159
提问于:2017-10-13 09:24
< >
分享
最佳答案
1

用你的虚拟机ping 一下你的本机地址,看是是否能ping通。

修改链接字符串为你的本机ip

把数据库的远程访问给打开。

收获园豆:10
Bluto | 菜鸟二级 |园豆:317 | 2017-10-13 17:44

谢谢

wall-ee | 园豆:159 (初学一级) | 2017-10-13 18:09

我的本地sqlserver express数据库安装时采用的是windows身份验证,我要是发布到虚拟机上,应该如何设置连接字符串才能访问到呢?麻烦您帮忙看一下

wall-ee | 园豆:159 (初学一级) | 2017-10-16 13:43

还有就是需要在虚拟机上面安装一个sqlserver2017的客户端吗?

wall-ee | 园豆:159 (初学一级) | 2017-10-16 13:57

@wall-ee: 把数据库里的sa用户给激活就行了。

Bluto | 园豆:317 (菜鸟二级) | 2017-10-16 13:57

@曲廉卿: 我激活了之后在connectionstring里面使用userid和password进行登陆,但data source还是computername/instance的格式,然后这样还是不行,请教一下我该继续怎么做。。。谢谢您

wall-ee | 园豆:159 (初学一级) | 2017-10-16 14:36

@wall-ee:  Microsoft.EntityFrameworkCore.Database.Connection[200004]
      An error occurred using the connection to database 'CustomerInformationReporter' on server 'JIANXIN\SQLEXPRESS'.
System.Data.SqlClient.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: 44 - Could not compose Service Principal Name (SPN) for Windows Integrated Authentication. Possible causes are server(s) incorrectly specified to connection API calls, Domain Name System (DNS) lookup failure or memory shortage) ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (0x00000005): No such device or address
   at System.Net.Dns.InternalGetHostByName(String hostName, Boolean includeIPv6)
   at System.Net.Dns.GetHostEntry(String hostNameOrAddress)
   at System.Data.SqlClient.SNI.SNIProxy.GetSqlServerSPN(String hostNameOrAddress, String portOrInstanceName)
   at System.Data.SqlClient.SNI.SNIProxy.GetSqlServerSPN(DataSource dataSource)
   at System.Data.SqlClient.SNI.SNIProxy.CreateConnectionHandle(Object callbackObject, String fullServerName, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Byte[]& instanceName, Byte[]& spnBuffer, Boolean flushCache, Boolean async, Boolean parallel, Boolean isIntegratedSecurity)
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling)
   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, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionPool.WaitForPendingOpen()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.<OpenAsync>d__34.MoveNext()
ClientConnectionId:00000000-0000-0000-0000-000000000000

wall-ee | 园豆:159 (初学一级) | 2017-10-16 14:48

@wall-ee: 错误很明显呀,你的数据库连接字符串不对。

Bluto | 园豆:317 (菜鸟二级) | 2017-10-16 15:30

@wall-ee: 把你的的appsetting.json 的connectionstring节点内容 贴出来

Bluto | 园豆:317 (菜鸟二级) | 2017-10-16 15:31

@wall-ee: computername/instance的格式 改为  0.0.0.0 试一试。

Bluto | 园豆:317 (菜鸟二级) | 2017-10-16 15:32

@曲廉卿: 搞定了,感谢,需要在sql server中设置支持远程访问,然后吧data source改成0.0.0.0,port格式的

wall-ee | 园豆:159 (初学一级) | 2017-10-16 15:59
其他回答(1)
0

错误提示是什么?

Timetombs | 园豆:3954 (老鸟四级) | 2017-10-13 09:34

就是提示entityframework访问不到数据库

支持(0) 反对(0) wall-ee | 园豆:159 (初学一级) | 2017-10-16 13:58

 Microsoft.EntityFrameworkCore.Database.Connection[200004]
      An error occurred using the connection to database 'CustomerInformationReporter' on server 'JIANXIN\SQLEXPRESS'.
System.Data.SqlClient.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: 44 - Could not compose Service Principal Name (SPN) for Windows Integrated Authentication. Possible causes are server(s) incorrectly specified to connection API calls, Domain Name System (DNS) lookup failure or memory shortage) ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (0x00000005): No such device or address
   at System.Net.Dns.InternalGetHostByName(String hostName, Boolean includeIPv6)
   at System.Net.Dns.GetHostEntry(String hostNameOrAddress)
   at System.Data.SqlClient.SNI.SNIProxy.GetSqlServerSPN(String hostNameOrAddress, String portOrInstanceName)
   at System.Data.SqlClient.SNI.SNIProxy.GetSqlServerSPN(DataSource dataSource)
   at System.Data.SqlClient.SNI.SNIProxy.CreateConnectionHandle(Object callbackObject, String fullServerName, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Byte[]& instanceName, Byte[]& spnBuffer, Boolean flushCache, Boolean async, Boolean parallel, Boolean isIntegratedSecurity)
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling)
   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, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionPool.WaitForPendingOpen()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.<OpenAsync>d__34.MoveNext()
ClientConnectionId:00000000-0000-0000-0000-000000000000

支持(0) 反对(0) wall-ee | 园豆:159 (初学一级) | 2017-10-16 14:48
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册