unity3d怎么使c#连接数据库
发布网友
发布时间:2022-10-10 08:54
我来回答
共1个回答
热心网友
时间:2023-10-05 23:09
Unity3d连接SQL Server数据库:
首先需要把Unity安装路径下的System.Data.dll和Mono.Data.SqliteClient.dll拷贝到当前unity工程的Assets文件夹下,因为之后在脚本中引用的.dll并不是framework提供的。脚本的内容:
using UnityEngine;
using System;
using System.Collections;
using System.Data;(这个必须是引用自unity的安装目录下,如果找不到就搜索一下)
using System.Data.SqlClient;
public class ConnectSQL : MonoBehaviour
{
// Use this for initialization
void Start()
{
string connectionString = "Data Source=XYL-PC;DataBase=Unity;uid=sa;pwd=123456;";
SqlConnection con = new SqlConnection();
con.ConnectionString = connectionString;
con.Open();
if (con.State == ConnectionState.Open)
{
print("Connect success!");
}
else
{
print("Connect Failure!");
}
}
}