c# - Android C# 本地网络访问
问题描述
我正在开发要部署在仓库中的 android 应用程序,但在访问192.168.8.*
网络上的 SQL 数据库时遇到问题。它在调试中工作正常,但是当我在发行版中部署它时,它无法建立连接。
由于这都是内部的,我直接在 SQL 上运行查询,而不是创建服务层。
任何指针将不胜感激。
我的连接字符串是这样的
Server={0};Database=Database;User Id={1};Password={2};Connection Timeout=10;
代码:
public static string ReturnString(string query, string expectedDataType =
"STRING")
{
SqlConnection connection = null;
try
{
using (connection = new SqlConnection(GetConnectionString()))
{
//open connection
connection.Open();
SqlCommand command = new SqlCommand(query, connection);
command.Connection = connection;
command.CommandText = query;
var result = command.ExecuteScalar();
//close connection
connection.Close();
//see if there is a table to return
if (expectedDataType == "INT" && (result == System.DBNull.Value || result == null))
{
return "0";
}
if (result != "" && (result != null && result != System.DBNull.Value))
{
return result.ToString();
}
}
}
catch (Exception exception)
{
#region connection error
Console.Write("ERROR IS HERE: " + exception);
#endregion
}
finally
{
if (connection.State == ConnectionState.Open)
{
connection.Close();
}
}
return null;
}
解决方案
推荐阅读
- php - 在 laravel 中插入数据并登录
- c++ - 在所有子标题中包含基本标题的问题
- svg - Stroke-dashoffset, 位置 stroke-dasharray
- symfony - 在存储库中将 sql 转换为 docrine
- excel - find the row number of the first empty cell in the first column in excel via vbs
- reactjs - 如何将异步数据传递给调度动作,以便我可以在动作创建者中使用它?
- cucumber - java intellij中不同stepdefs中的黄瓜步骤重复
- c# - 查询返回查询,而不是结果
- asp.net - 使用 Excel VBA 打开 IE 并与 Web 表单交互
- python - TypeError: get_tier_by_name() 在 Pycharm 中正好采用 2 个参数(3 个给定)