I keep getting this error database schema has changed near "1": syntax error
.
I am not changing my schema in the code. This is the code where I make the schema. wish to try each answer in order that you posted it. This code is used to transfer a database to another database program. So it has to be compatible with more then one database program.
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;
}
}
This is the part where the sqlite schema has changed arror occurs.
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);
I believe that instead of SELECT TOP 1 *
you need to be using SELECT * FROM .... LIMIT 1
You need to check nameTable is null or empty
if(!string.IsNullOrEmpty(fullTableName))
string sql = string.Format("SELECT * FROM {0} LIMIT 1", fullTableName);
for SQLLITE
SELECT * FROM Table_Name LIMIT 1;
for SQL
SELECT TOP 1 * FROM Table_Name;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With