数据库模式已更改
本文关键字:模式 数据库 | 更新日期: 2023-09-27 18:10:44
我一直得到这个错误database schema has changed near "1": syntax error
。
我没有在代码中改变我的模式。这是我创建模式的代码。希望按照你发布的顺序尝试每个答案。此代码用于将数据库传输到另一个数据库程序。因此,它必须与多个数据库程序兼容。
public DataTable GetSchemaTable(string schema, string nameTable)
{
switch (m_dbType)
{
case dbTypeEnum.Sqlite:
//Make the schema of the source table
MakeConnectionString();
string fullTableName = schema.Length > 0
? string.Format("[{0}].[{1}]", schema, nameTable)
: string.Format("[{0}]", nameTable);
if (!string.IsNullOrEmpty(fullTableName))
{
string sql = string.Format("SELECT * FROM {0} LIMIT 1", fullTableName);
DataTable dtSchemaSource;
try
{
using (IDataReader rdr = ReadOnlyForwardOnly(sql))
{
dtSchemaSource = rdr.GetSchemaTable();
}
}
finally
{
CloseConnection();
}
if (dtSchemaSource == null)
{
throw new RadGeneralException("rdr.GetSchemaTable() returns null with sql = " + sql);
}
return dtSchemaSource;
}
break;
default:
//Make the schema of the source table
MakeConnectionString();
string fullTableName = schema.Length > 0
? string.Format("[{0}].[{1}]", schema, nameTable)
: string.Format("[{0}]", nameTable);
string sql = string.Format("SELECT TOP 1 * FROM {0}", fullTableName);
DataTable dtSchemaSource;
try
{
using (IDataReader rdr = ReadOnlyForwardOnly(sql))
{
dtSchemaSource = rdr.GetSchemaTable();
}
}
finally
{
CloseConnection();
}
if (dtSchemaSource == null)
{
throw new RadGeneralException("rdr.GetSchemaTable() returns null with sql = " + sql);
}
return dtSchemaSource;
}
}
这是发生sqlite模式已更改错误的部分。
StringBuilder sbColList = new StringBuilder();
nCol = 0;
identityColInBothTables = false;
//Make the schema of the source table
DataTable dtSchemaSource = objDbSource.GetSchemaTable(SchemaSource, Name);
//Make the schema of the target table
DataTable dtSchemaTarget = objDbTarget.GetSchemaTable(SchemaTarget, Name);
我认为你应该使用SELECT * FROM .... LIMIT 1
而不是SELECT TOP 1 *
您需要检查nameTable是否为空
if(!string.IsNullOrEmpty(fullTableName))
string sql = string.Format("SELECT * FROM {0} LIMIT 1", fullTableName);
为SQLLITE这样SELECT * FROM Table_Name LIMIT 1;
为SQL SELECT TOP 1 * FROM Table_Name;
你可以试试这个吗:
SELECT * FROM SAMPLE_TABLE ORDER BY ROWID ASC LIMIT 1