c# - 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)
返回真
请帮忙!
解决方案
好的,我花了两天时间寻找解决此问题的方法并找到了。
首先转到编辑 > 项目设置 > 播放器。在“其他选项”中将“Scripting Runtime Version”更改为“.NET 4.x Equivalent”,将“Api Compatibility Level”更改为“.NET 4x”,重新启动 Unity,然后转到 Unity\Editor\Data\MonoBleedingEdge\lib\mono \4.5 并将 System.Data.dll 复制到您的项目文件夹中。
最后它起作用了!
推荐阅读
- rest - 在进行破坏性 API 更改时,有哪些方法可以确保向后兼容性?
- ios - 如何更改 uialertcontroller 的文本字段内容?
- java - 如何使用 azure-documentdb 在 java 代码中的数据库级别配置吞吐量
- node.js - TS:无法调用其类型在动态定义时缺少调用签名的表达式,但它可以工作
- javascript - 在 ThreeJS 中获取局部对象旋转
- android - Android:使用协程测试视图模型
- android-studio - Android Studio Flutter UI 指南不起作用
- javascript - 如何让我的机器人从一组图像中选择一个随机图像
- instance - 可以将抢占式实例更改为非抢占式吗
- amazon-web-services - IAM 角色不适用于 golang Docker 容器