首页 > 解决方案 > SqlDependency.Start 在 Unity 中不起作用?

问题描述

我正在创建一个简单的客户端服务器应用程序,但我遇到了 sql。当我运行代码时

using System.Data;
class Program
{
    static void Main(string[] args)
    {
         SqlDependency.Start("server=111.111.111.111;database=db;Persist Security Info=false;Integrated Security=false;User Id=user;Password=password");
    }
}

然后我在 SQL Server 上的数据库中的服务代理中看到正确创建的队列和服务

但是当我从统一运行类似的代码时:

using System.Data;
public class ABC : MonoBehaviour 
{
    void Start()
    {
        System.Data.SqlClient.SqlDependency.Start("server=111.111.111.111;database=db;Persist Security Info=false;Integrated Security=false;User Id=user;Password=password")
    }
}

然后没有创建队列和服务,并且控制台中没有错误。

无论这段代码在哪里执行,SqlDependency.Start 都不起作用。我尝试使用不同版本的 system.data.dll 但没有帮助。

bool a=System.Data.SqlClient.SqlDependency.Start("server=111.111.111.111;database=db;Persist Security Info=false;Integrated Security=false;User Id=user;Password=password")
Debug.Log(a)

返回真

请帮忙!

标签: c#unity3d

解决方案


好的,我花了两天时间寻找解决此问题的方法并找到了。

首先转到编辑 > 项目设置 > 播放器。在“其他选项”中将“Scripting Runtime Version”更改为“.NET 4.x Equivalent”,将“Api Compatibility Level”更改为“.NET 4x”,重新启动 Unity,然后转到 Unity\Editor\Data\MonoBleedingEdge\lib\mono \4.5 并将 System.Data.dll 复制到您的项目文件夹中。

最后它起作用了!


推荐阅读