在将msaccess db转换为sql的同时,我收到了错误,例如IErrorInfo.GetDescription失败了E_FAIL(0x80004005) [英] I got error like this IErrorInfo.GetDescription failed with E_FAIL(0x80004005) while converting msaccess db to sql
本文介绍了在将msaccess db转换为sql的同时,我收到了错误,例如IErrorInfo.GetDescription失败了E_FAIL(0x80004005)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在执行查询以将数据库从msaccess传输到SQL时,出现了'IErrorInfo.GetDescription使用E_FAIL(0x80004005)'失败的错误。
。
我写了这段代码
I got the error like this 'IErrorInfo.GetDescription failed with E_FAIL(0x80004005)'.
while executing the query to transfer the database from msaccess to SQL.
I have written this code
DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb");
DataTable userTables = null;
using (connection)
{
string mappath = dataGridView1.CurrentRow.Cells["Path"].Value.ToString();
string[] filePaths = Directory.GetFiles(@"" + mappath + "", "*.mdb", SearchOption.TopDirectoryOnly);
// c:\test\test.mdb
foreach (string tr in filePaths)
{
connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + tr + "";
string[] restrictions = new string[4];
restrictions[3] = "Table";
connection.Open();
userTables = connection.GetSchema("Tables", restrictions);
List<string> tableNames = new List<string>();
for (int i = 0; i < userTables.Rows.Count; i++)
tableNames.Add(userTables.Rows[i][2].ToString());
try
{
foreach (string tableName in tableNames)
{
//cn1 = new SqlConnection(con);
//if (cn1.State != ConnectionState.Open) { cn1.Open(); }
//SqlCommand cmd = new SqlCommand("select * into [" + tableName + "] from OPENROWSET('Microsoft.Jet.OLEDB.4.0','" + tr + "';'Admin';'',[" + tableName + "])");
//cmd.Connection = cn1;
//cmd.ExecuteNonQuery();
OleDbCommand cmd = new OleDbCommand("select * into ["+tableName+"] IN "+con+" FROM ["+tableName+"]",connection);
cmd.ExecuteNonQuery();
connection.Close();
}
}
catch (Exception Ex) { connection.Close(); }
connection.Close();
}
}
}
catch (Exception Ex) { }
查询是这样的
And the query is like this
select * into [ACTYPE] IN ODBC; Driver={SQL Server};Server='PC01';Initial Catalog=TARR;Persist Security Info=True;User ID= 'sa';Password='123' FROM [ACTYPE]
你愿意吗解决此错误。
Would u pls resolve this error.
推荐答案
抱歉... 错误的方法!
使用安全类: SqlBulkCopy [ ^ ]。
如何使用它(一步一步)?
1.创建连接 [ ^ ]到MS Access数据库
2.将MS Access数据库中的数据加载到 DataTable [ ^ ]
3.断开MS Access数据库(执行不删除数据表对象!)
4.创建连接 [ ^ ]到MS SQL Server数据库
5.在其中使用datatable对象 SqlBulkCopy.WriteToServer [ ^ ]在数据库之间复制数据的方法
6.断开MS SQL Server
这就是全部!
Sorry... Wrong approach!
Use safe class: SqlBulkCopy[^].
How to use it (step by step)?
1. Create connection [^]to MS Access database
2. Load data from MS Access database into DataTable[^]
3. Disconnect MS Access database (do NOT remove datatable object!)
4. Create connection[^] to MS SQL Server database
5. Use datatable object within SqlBulkCopy.WriteToServer[^] method to copy data between databases
6. Disconnect MS SQL Server
That's all!
这篇关于在将msaccess db转换为sql的同时,我收到了错误,例如IErrorInfo.GetDescription失败了E_FAIL(0x80004005)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文