1、找到System.Data.dll文件,默认的地址是在C:Program FilesUnityEditorDataMonolibmonounity,这个根据你所安装的路径有关。

2、将该文件复制到你的工作空间下的Asset文件夹内
3、在你的编辑器中添加引用,我用的是VS


4、在命名空间内增加程序集
using System;
using System.Data;
using System.Data.SqlClient;
5、编写连接数据库代码
SqlConnection con = null;
SqlDataAdapter sda = null;
void Start()
{
string s = @"server=.;database=ConnectTest;uid=sa;pwd=123456"; //注意,这里必须使用SQL Server和Windows验证模式,否则会报错
con = new SqlConnection(s);
con.Open();
string sql = "select * from table1";
sda = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
sda.Fill(ds, "table1");
print(ds.Tables[0].Rows[0][0]);
}
6、实验结果
