尝试通过Uniy创建数据库时发生错误。
以下是通过引用“ Mono.Data.Sqlite”创建的DLL文件。
public class DbCon
{
private String Path;
private SqliteConnection connection;
private SqliteCommand Command;
public DbCon(String nPath)
{
Path = nPath;
}
private string getCoonectingString()
{
string strCon = String.Format(@"Data Source={0};Version=3;New=True;Compress=False;Read Only=False;MultipleActiveResultSets=True", Path);
return strCon;
}
public bool IsConnected()
{
if (connection != null && connection.State == System.Data.ConnectionState.Open)
return true;
return false;
}
public bool connect()
{
if (IsConnected() == true) return true;
connection = new SqliteConnection(getCoonectingString());
try
{
connection.Open();
if (connection.State == System.Data.ConnectionState.Open)
{
Command = new SqliteCommand();
Command.Connection = connection;
return true;
}
}
catch
{
return false;
}
return false;
}
private DataTable GetTable()
{
DataTable dataTable = new DataTable();
dataTable.Columns.Add("NAME", typeof(string));
dataTable.Columns.Add("EADATE", typeof(string));
dataTable.Columns.Add("LATIUDE", typeof(string));
dataTable.Columns.Add("HLTIUDE", typeof(string));
dataTable.Columns.Add("LRAD", typeof(Double));
dataTable.Columns.Add("NRAD", typeof(Double));
dataTable.Columns.Add("MRAD", typeof(Double));
dataTable.Columns.Add("NNL", typeof(string));
dataTable.Columns.Add("CREATDATE", typeof(string));
dataTable.Columns.Add("EDITDATE", typeof(string));
return dataTable;
}
/// <summary>
/// NAME
/// </summary>
/// <returns>DataTable</returns>
public DataTable GetNameListSel()
{
DataTable table = new DataTable();
table.Columns.Add("NAME", typeof(string));
String queryString = String.Format("SELECT DISTINCT NAME from IFPUG ");
Command.CommandText = queryString;
table.Load(Command.ExecuteReader());
Command.ExecuteReader().Close();
return table;
}
}
该脚本是通过引用Unity来制作的。
void Start()
{
string str = "C:/SEA.s3db";
DbCon nCon;
nCon = new DbCon(str);
bool result = nCon.connect();
Debug.Log(result);
if (result == true)
{
table = nCon.GetNameListSel();
Debug.Log("11");
}
else
{
Debug.Log("22");
}
}
我使用上面的脚本运行了该函数,但是我检查是否已连接,但是在运行该函数的那部分一直出现错误。
{InvalidOperationException: DataReader already active on this command}
我需要你的帮助。请让我活下去。