我是新手。事实上,这是我第一次在stackoverflow上发布一个问题。我做了很多搜索但却找不到答案。 这是我要做的事情的要点。
这是文件发生的事情。
这是我徒劳无功的尝试。
这是我打算做的。
使用Try Catch来捕获错误。
cn = new ADODB.Connection();
cat = new ADOX.CatalogClass();
cn.Open(tmpStr);
cat.ActiveConnection = cn;
//Loop through all tables to add the validation text
foreach (Table t in cat.Tables)
{
tname = t.Name;
ttype = t.Type == null ? string.Empty : t.Type;
tprop = t.Properties["Jet OLEDB:Table Hidden In Access"].Value.ToString();
if (ttype.ToUpper() == "TABLE" && tprop.ToUpper() == "FALSE") //
{
t.Properties["Jet OLEDB:Table Validation Text"].Value = "this is table " + tname + " student1";
}
//System.Runtime.InteropServices.Marshal.FinalReleaseComObject(t);
}
//Close all open objects
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(cat.Tables);
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(cat.ActiveConnection);
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(cat);
GC.Collect();
你认为我想要完成我想做的事情的方式有什么问题吗?谢谢你,祝你有个美好的一天。
答案 0 :(得分:1)
我很长时间没有使用ADODB,但根据我的记忆: 你应该关闭连接,GC.Collect()将"最终"收集孤儿对象,但我相信你应该使用Connection对象的Close方法。 https://msdn.microsoft.com/en-us/library/ms807027.aspx