我正在尝试使用 Xamarin 和 C# 通过 SqlClient 连接到数据库。该代码在命令行上运行良好,但是当我尝试在 Xamarin Live Player 上执行它时,它会返回一个错误,提示“找不到编码 1252 数据”。
我试过检查 iOS 选项中的“west”框,就像我在网上找到的一样,但它并没有解决我的问题。我也尝试通过 apk 安装应用程序,而不是通过 xam live player 运行它,但它在启动时崩溃。
这是我的代码:
void DatabaseConnection()
{
string str = "";
SqlCommand command;
SqlDataReader dataReader;
using (SqlConnection connection = new SqlConnection("Data Source = db_ip; Initial Catalog = list_name; Persist Security Info = True; User ID = my_user; pwd = my_pass;"))
{
connection.Open();
command = new SqlCommand("my_command", connection);
dataReader = command.ExecuteReader();
while (dataReader.Read())
{
str += dataReader.GetValue(1) + " - ";
}
Output.Text = str;
}
}
它应该返回“171 -”,但正如我上面所说,它只是崩溃了。我无法解决这个问题,有人可以帮助我吗?