简体   繁体   English

SQL 服务器与 Unity3D

[英]SQL Server with Unity3D

I want to use SQL Server with Unity.我想将 SQL 服务器与 Unity 一起使用。 I add System.Data.dll to assets in Unity project but I get this error:我将System.Data.dll添加到 Unity 项目中的资产,但出现此错误:

The type or namespace name 'SqlClient' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)命名空间“System.Data”中不存在类型或命名空间名称“SqlClient”(您是否缺少程序集引用?)

Then I added sqlclient.dll to the assets folder, but I still get:然后我将sqlclient.dll添加到 assets 文件夹中,但我仍然得到:

The type name 'SqlConnection' could not be found in the namespace 'System.Data.SqlClient'.在命名空间“System.Data.SqlClient”中找不到类型名称“SqlConnection”。 This type has been forwarded to assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.此类型已转发到程序集“System.Data,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089”。
Consider adding a reference to that assembly.考虑添加对该程序集的引用。

Please help me?请帮我? What's wrong?怎么了?

After some researches, looks like there are much easy way to import sql in new versions of Unity:经过一些研究,看起来在新版本的 Unity 中导入 sql 有很多简单的方法:

  1. Download new System.Data.SqlClient from nuget.从 nuget 下载新的 System.Data.SqlClient。 For example, use in terminal nuget install System.Data.SqlClient -Version 4.7.0 -OutputDirectory <some temp dir>例如,在终端nuget install System.Data.SqlClient -Version 4.7.0 -OutputDirectory <some temp dir>
  2. Open unity build settings, find Api Compatibility Level .打开 unity build settings,找到Api Compatibility Level It will be .NET 4.x or .NET Standard 2.0它将是.NET 4.x.NET Standard 2.0
  3. Create Plugins directory in folder在文件夹中创建Plugins目录
  4. Copy dll from <some temp dir>/lib/<api level>/System.Data.SqlClient.dll to Plugins directory.将 dll 从<some temp dir>/lib/<api level>/System.Data.SqlClient.dllPlugins目录。
  5. That all, you can use sql:)这一切,你可以使用 sql :)

For example, in my case there are .NET Standard 2.0 compat.例如,在我的情况下,有.NET Standard 2.0兼容。 level and <some temp dir>/lib/netstandard2.0/System.Data.SqlClient.dll library.级别和<some temp dir>/lib/netstandard2.0/System.Data.SqlClient.dll库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM