我正在开发一个要在仓库中部署的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;
}