Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Triggers BCP忽略触发器,我能做什么?_Triggers_Bcp - Fatal编程技术网

Triggers BCP忽略触发器,我能做什么?

Triggers BCP忽略触发器,我能做什么?,triggers,bcp,Triggers,Bcp,当我在数据库中使用BCP数据时,触发器不会被触发。 我应该怎么做才能使触发器有用?我可以只更新数据而不更改值吗 try { //get all data string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + excelFile + ";" + "Extended Properties=Excel 8.0;";

当我在数据库中使用BCP数据时,触发器不会被触发。 我应该怎么做才能使触发器有用?我可以只更新数据而不更改值吗

     try
        {
            //get all data
            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + excelFile + ";" + "Extended Properties=Excel 8.0;";
            OleDbConnection conn = new OleDbConnection(strConn);
            conn.Open();
            string strExcel = "";
            strExcel = string.Format("select * from [{0}$] where xh<>''", sheetName);
            OleDbDataAdapter oda = new OleDbDataAdapter(strExcel, strConn);
            oda.Fill(ds, sheetName);

            //BCP data
            using (SqlBulkCopy bcp = new SqlBulkCopy(connectionString))
            {
                bcp.SqlRowsCopied += new SqlRowsCopiedEventHandler(bcp_SqlRowsCopied);
                bcp.BatchSize = 100;//the speed of import
                bcp.NotifyAfter = 100;
                bcp.DestinationTableName = sheetName;//target table
                bcp.WriteToServer(ds.Tables[0]);
            }
        }
   catch (Exception ex)
        {
            System.Windows.Forms.MessageBox.Show(ex.Message);
        }
试试看
{
//获取所有数据
字符串strConn=“Provider=Microsoft.Jet.OLEDB.4.0;”“+”数据源=“+excelFile+”;“+”扩展属性=excel8.0;”;
OLEDB连接连接=新的OLEDB连接(strConn);
conn.Open();
字符串strExcel=“”;
strExcel=string.Format(“select*from[{0}$],其中xh'',sheetName);
OleDbDataAdapter oda=新的OleDbDataAdapter(strExcel,strConn);
oda.填写(ds,表名);
//BCP数据
使用(SqlBulkCopy bcp=newsqlbulkcopy(connectionString))
{
bcp.SqlRowsCopied+=新的SqlRowsCopiedEventHandler(bcp_SqlRowsCopied);
bcp.BatchSize=100;//导入的速度
bcp.after=100;
bcp.DestinationTableName=sheetName;//目标表
bcp.WriteToServer(ds.Tables[0]);
}
}
捕获(例外情况除外)
{
System.Windows.Forms.MessageBox.Show(例如Message);
}
触发器在后面

创建触发器获取
在tablename上
对于插入,请更新
作为
如果更新(生日)
更新tablename set age=DateDiff(年、生日、getdate())
请查看此MSDN文章:

使用bcp时,默认情况下禁用触发器。要启用它,请使用以下参数:

-h "FIRE_TRIGGERS"

使用.NET提供的类时,请使用枚举启用触发器。

我找到了这个解决方案,但我不理解它。你能更具体地解释一下吗?谢谢。显然SQL Server禁用了触发器,但没有将其标记为已禁用(在sys.triggers中),并且在完成bcp后不会重新启用触发器。我会称之为bug。此外,应该指出DATEDIFF(Year,birth,GETDATE())是一种非常不可靠的返回年龄的方法。尤其是在新年那天,几乎每个人都会计算出错误的年龄