Xamarin连接Microsoft SQL Server数据库时出现连接错误求助
毕业设计App连接SQL Server数据库问题求助
我正在为学校毕业设计开发Android和iOS应用,这是我第一次接触数据库,完全毫无头绪,老师也没法提供帮助,所以来求助。
我在PC上运行Android Studio和Microsoft SQL Server数据库,知道可能需要开发REST API,但目前只想先在PC上完成应用测试。
我尝试了如下代码和其他方法,但核心问题是连接错误。我的PC IP是192.168.1.41,使用Android 13系统的Pixel模拟器,数据库名为personeelgegevens,SQL Server实例名为HP_PROBOOK_G8\MSSQLSERVER02。代码在执行con.Open();时崩溃报错。
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data; using System.Data.SqlClient; using Xamarin.Forms; using Xamarin.Forms.Xaml; namespace ShowMeYourTools { [XamlCompilation(XamlCompilationOptions.Compile)] public partial class LoginUI : ContentPage { public LoginUI() { InitializeComponent(); } //登录按钮 private void Button_Clicked(object sender, EventArgs e) { if (txbEmail.Text == "ADMIN" && txbWachtwoord.Text == "ADMIN") { Navigation.PushModalAsync(new ShowMeYourTools.HomePage()); } else { DisplayAlert("输入错误", "输入信息与我们记录的账户不匹配。", "确定"); } } //未使用 private void Button_Clicked_1(object sender, EventArgs e) { string constring = @"Server=192.168.1.41;Database=personeelgegevens;Trusted_Connection=true"; using (SqlConnection con = new SqlConnection(constring)) { try { con.Open(); DisplayAlert("成功", "已连接数据库", "确定"); } catch (Exception ex) { DisplayAlert("错误", ex.ToString(), "确定"); } } } //忘记密码文本点击事件 private void TapGestureRecognizer_Tapped(object sender, EventArgs e) { Navigation.PushModalAsync(new ShowMeYourTools.PasswordReset()); } } }
补充:报错信息截图仅显示部分内容。
更新:更换互联网提供商(从Proximus改为Telenet)后,该问题已解决。
内容的提问来源于stack exchange,提问作者Thomas
相关产品推荐
相关产品推荐

