Android Xamarin SqlServer无法获得连接
我正在使用xamarin上的实体框架构建一个应用程序,我在其中比较了一些数据。但当我启动“fetchdata”函数时,我收到了错误:Android Xamarin SqlServer无法获得连接,android,.net,sql-server,xamarin,core,Android,.net,Sql Server,Xamarin,Core,我正在使用xamarin上的实体框架构建一个应用程序,我在其中比较了一些数据。但当我启动“fetchdata”函数时,我收到了错误: System.Data.SqlClient.SqlException (0x80131904): Snix_Connect (provider: SNI_PN7, error: 35 - SNI_ERROR_35)Snix_Connect (provider: SNI_PN7, error: 35 - SNI_ERROR_35) 现在我的hole设置已经准备好
System.Data.SqlClient.SqlException (0x80131904): Snix_Connect (provider: SNI_PN7, error: 35 - SNI_ERROR_35)Snix_Connect (provider: SNI_PN7, error: 35 - SNI_ERROR_35)
现在我的hole设置已经准备好了,我看到了很多关于xamarin/android的帖子&不可能连接到SqlServer。但是时间过得很快,所以我希望这是可能的
是否有任何方法可以从xamarin上具有.net内核的sqlServer获取数据?是的,这是可能的(HuurrAYY!):
我是.NETCore、c#等领域的新手,对我来说,让它工作起来真是一件苦差事。。
下面是其他寻求帮助的noob:
我使用的指南:
使用实体框架构建Android应用程序
脚手架
我是如何做到的:
- Microsoft.EntityFrameworkCore
- Microsoft.EntityFrameworkCore.SqlServer
[编辑:在每个解决方案中都需要NuGets]这是我用SQL\u Common.cs放入SQL\u类文件夹的字符串
用实际参数填充支架(也拆下支架制动器) 然后,我可以随时从任何xamarin代码访问它,就像我们在asp.net c#
这在我的应用程序上对我有效,没有任何问题
using (SqlConnection Sql_Connection = new SqlConnection(Sql_Common.saralEHR_connection_string))
但正如@Jason在他的第一次回复中提到的,我也会再次检查安全部分。我在将软件包发布到Google Play之前有过经验,他们使用哈希密钥代码加密应用程序文件,然后只将其上传到服务器上。我正在这样做(工作片段):
它工作正常,但API调用更优雅。
我希望这会有所帮助。您可以从移动客户端直接连接到SQL server,这只是一个可怕的想法。你有没有检查过你的服务器是否可以从你的移动设备访问,所有相关端口是否打开,是否没有防火墙问题,等等?杰普,我根本没有注意到用“老派”的方式来做这件事,我现在下载了SQLApp,它连接了。。
using (SqlConnection Sql_Connection = new SqlConnection(Sql_Common.saralEHR_connection_string))
string connectionString = @"data source={server};initial catalog={database};user id={user};password={password};Connect Timeout=10";
string databaseTable = "{table name}";
string selectQuery = String.Format("SELECT count(*) as Orders FROM {0}", databaseTable);
try
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
//open connection
connection.Open();
SqlCommand command = new SqlCommand(selectQuery, connection);
command.Connection = connection;
command.CommandText = selectQuery;
var result = command.ExecuteScalar().ToString();
//check if there is result
if(result != null)
{
OrdersLabel.Text = result;
}
}
}
catch (Exception ex)
{
OrdersLabel.Text = ex.Message;
}