Question by
wjdru124 · Oct 30, 2018 at 10:51 AM ·
c#javascripterrorsqlite
Error) DataReader already active on this command
An error occurred while attempting to create a DB through the Unity.
Below is a dll file created by referring to "Mono.Data.Sqlite".
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;
}
}
This script was taken by referring to 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");
}
}
I ran the function with the script above, but I checked to be connected, but I keep getting an error in the part where I run the function.
InvalidOperationException: DataReader already active on this command
I need your help. Please let me live.
Comment