SqlSugarScope linux下链接SqlServer报错 返回
linux下面我有两个服务,
1.一个服务使用的 SqlSugarClient,链接的时候没有任何问题
services.AddScoped<ISqlSugarClient>(o =>
{
var db2 = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = ConnectionString,//连接符字串
DbType = DbType.SqlServer,
IsAutoCloseConnection = true,
MoreSettings = new ConnMoreSettings()
{
IsWithNoLockQuery = true//看这里
}
});2. 后面新加了一个服务,升级了一下这里,全部替换成了 SqlSugarScope
var db = new SqlSugarScope(new ConnectionConfig()
{
ConnectionString = ConnectionString,//连接符字串
DbType = DbType.SqlServer,
IsAutoCloseConnection = true,
MoreSettings = new ConnMoreSettings()
{
IsWithNoLockQuery = true//看这里
},
},链接报错:
English Message : Connection open error . 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: TCP Provider, error: 25 - Connection string is not valid)\r\nChinese Message : 连接数据库过程中发生错误,检查服务器是否正常连接字符串是否正确,实在找不到原因请先Google错误信息: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: TCP Provider, error: 25 - Connection string is not valid).
后面用这个地址在本地是可以的,一上linux环境就报错,之前的服务可以用,升级了一下就用不了
<ItemGroup> <PackageReference Include="SqlSugarCore" Version="5.0.4" /> </ItemGroup>
这个是这个包的问题吗?
热忱回答(31)
-
fate stay night VIP0
2021/9/26SQL Server is configured to allow remote connections.
这个错是没连接上远程吧
0 回复 -
fate stay night VIP0
2021/9/26你在服务器找找原因理论上和
SqlSugarScope没关系 ,写个简单的DEMO测试一下0 回复 -
没有谁离不开谁 VIP0
2021/9/26@fate stay night:噢噢,好的,我也觉得,我在开发服务器上没有报错,一到测试服务器就报错,我在找找。。
0 回复 -
没有谁离不开谁 VIP0
2021/9/26@fate stay night:给的账户权限的问题,我用的同一个数据库链接,在linux上面 SqlSugarClient可以使用, SqlSugarScope却不能用。 我在本地的时候都能使用。。。
0 回复 -
没有谁离不开谁 VIP0
2021/9/26@没有谁离不开谁: SqlSugarClient和SqlSugarScope 在链接数据库的时候处理不一样吗?
0 回复 -
fate stay night VIP0
2021/9/26@没有谁离不开谁:一样
0 回复 -
没有谁离不开谁 VIP0
2021/9/26@fate stay night:找到原因了。。。在linux服务器上面 SqlSugarScope 链接 Data Source=10.1.8.36\WAMSDB_DB002,1133; 这是带机器名的时候执行就会报那个错误, Data Source=10.1.8.36,1133; 这样执行的时候就可以了。
SqlSugarClient 都可以执行,这算啥类型的错误,算是SqlSugarScope 的问题吗
0 回复 -
没有谁离不开谁 VIP0
2021/9/26@fate stay night: 是不是没有识别 \ 字符啊
0 回复 -
fate stay night VIP0
2021/9/26@没有谁离不开谁: Linux \ 好像是反的吧,连接字符串能不用最好
0 回复 -
fate stay night VIP0
2021/9/26声名一下这2个没驱别 SqlSugarScope 只是封装了 SqlSugarClient 连数据库底层还是 SqlSugarClient
0 回复 -
没有谁离不开谁 VIP0
2021/9/26@fate stay night:好的,知道为啥了。 数据库配置是在配置中心配置的,使用 \\ 可以链接,应该是就是这个 \ 的问题,linux上面是 / ,是反着的,感谢啦~
0 回复 -
没有谁离不开谁 VIP0
2021/9/26@fate stay night:我改双 \\ 以前的SqlSugarClient 用不了。。 Dapper里面也不能用。 就SqlSugarScope能用。 SqlSugarScope 这个写的跟其他不一样啊
0 回复 -
fate stay night VIP0
2021/9/26@没有谁离不开谁:是一样的东西你找找原因吧,你的定位就不对,而不应该怀疑他们不一样
0 回复 -
没有谁离不开谁 VIP0
2021/9/26@fate stay night:好的
0 回复 -
fate stay night VIP0
2021/9/26你的错误思路一直在想为什么不一样,其实就是一样的东西这个东西是100%相等的,你应该去想一样的东西在不同的地方为什么不能用
0 回复 -
没有谁离不开谁 VIP0
2021/9/27@fate stay night:
SqlSugarScope :


换成双\\ ,同样的错误


不要\,接口能够调通


今天我做了一下测试,要实例名就会连不上,在本地windows上是可以练的,发布linux上就不行?
0 回复 -
没有谁离不开谁 VIP0
2021/9/27@fate stay night:

SqlSugarClient




我把版本降到原来的,可以成功,最新的版本链接字符串那边改过了吧


0 回复 -
没有谁离不开谁 VIP0
2021/9/27@fate stay night:版本问题,我还是使用5.0.3.4这个版本,可以用SqlSugarScope,也不会报错
0 回复 -
fate stay night VIP0
2021/9/27@没有谁离不开谁:建议用新版本,因为 2者区别是 sqlserver驱动不一样 , 新版本驱动性有是之前的几倍之快
0 回复 -
没有谁离不开谁 VIP0
2021/9/27@fate stay night:用新的版本,加 \就连不上,我也想用新版本啊
0 回复 -
fate stay night VIP0
2021/9/27还真给你找到原因了,建议用新版本的 Microsoft.Data.SqlClient ,以前System.Data.SqlClient 性能要慢的多, 至少在数倍
0 回复 -
fate stay night VIP0
2021/9/27正好这2者驱动处理\机质不一样
0 回复 -
fate stay night VIP0
2021/9/27@没有谁离不开谁:代码中处理一下 \的逻辑吧 如果驱动用什么新驱动用什么
0 回复 -
没有谁离不开谁 VIP0
2021/9/27@fate stay night:好的,我到时候看看怎么能用,能用就升级新的
0 回复 -
没有谁离不开谁 VIP0
2021/9/27@fate stay night:EFCore里面识别\,有时候可以看看封装的有啥问题~~
0 回复 -
fate stay night VIP0
2021/9/27@没有谁离不开谁: 没个么问题就是new SqlConnection(str) 驱动不一样而已
0 回复 -
fate stay night VIP0
2021/9/27认真看一下 Microsoft.Data.SqlClient 或者
System.Data.SqlClient 他们的版本号区别
0 回复 -
没有谁离不开谁 VIP0
2021/9/27@fate stay night:EFCore我用的包就是最新的,Microsoft.Data.SqlClient 这个驱动的,我试了字符串是可以的
0 回复 -
fate stay night VIP0
2021/9/270 回复 -
没有谁离不开谁 VIP0
2021/9/27@fate stay night:好的,谢谢啦
0 回复 -
fate stay night VIP0
2021/9/27@没有谁离不开谁:用原生写法去测
0 回复