C# Mysql异常无法连接到任何指定的主机-仅限WPF

C# Mysql异常无法连接到任何指定的主机-仅限WPF,c#,mysql,wpf,connection,C#,Mysql,Wpf,Connection,我知道类似的问题已经解决了,但这有点奇怪 当我尝试在WPF中使用Connector/NET连接到远程Mysql时,我得到一个XAMLParseException。内部异常表示它无法连接到任何指定的主机。 但是,当我尝试使用WinForms而不是WPF时,它工作得很好,所以我相信连接字符串、服务器设置和MySQL程序集都可以工作。所以问题可能在XAML中。这是MainWindow.xaml <Window x:Class="_min_t1.MainWindow" xmlns="htt

我知道类似的问题已经解决了,但这有点奇怪

当我尝试在WPF中使用Connector/NET连接到远程Mysql时,我得到一个XAMLParseException。内部异常表示它无法连接到任何指定的主机。 但是,当我尝试使用WinForms而不是WPF时,它工作得很好,所以我相信连接字符串、服务器设置和MySQL程序集都可以工作。所以问题可能在XAML中。这是MainWindow.xaml

<Window x:Class="_min_t1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <Label Content="Label" Height="58" HorizontalAlignment="Left" Margin="72,35,0,0" Name="label1" VerticalAlignment="Top" Width="161" />
</Grid>

但这正是VS为一个新项目所产生的结果


有什么想法吗?

XAML用于创建UI,因此不会影响您连接MySQL的方式。如果您可以从WinForms应用程序进行连接,则连接已正确设置。发布您获得的异常的堆栈跟踪。这是堆栈跟踪:或其顶部<代码>位于System.Windows.Markup.XamlReader.RewrapException(异常e,IXamlLineInfo lineInfo,Uri baseUri)位于System.Windows.Markup.WpfXamlLoader.Load(XamlReader XamlObjectWriterFactory writerFactory,Boolean skipJournaledProperties,Object rootObject,XamlObjectWriterSettings设置,Uri baseUri)在System.Windows.Markup.wpfxamloader.LoadBaml(XamlReader-XamlReader,Boolean skipJournaledProperties,Object-rootObject,XamlAccessLevel-accessLevel,Uri-baseUri)OK,它可能与xaml无关,我移动了连接到事件的位置,xaml异常消失了,但它仍然无法连接到任何主机-连接字符串:
“Server=109.74.158.75;Uid=…;Pwd=…;Database=ks;pooling=false”
,我想运行的整个代码是:
MySqlConnection conn=newmysqlconnection(connstring);conn.Open();label1.Content=conn.State.ToString();康涅狄格州关闭()刚刚开始工作,我在App.config中有错误的结构(回溯显示得很清楚,只是需要学习使用调试器:),很抱歉打扰您。。。