I'm currently in the process of writing a small script that exports the event log of a program and writes it to a database. However, I am having problems with my SQL insert command. What am I doing wrong? This is just a code cutout
string command = "DECLARE @x xml;";
command += "SELECT @x = P";
command += "FROM OPENROWSET(BULK 'C:\\Users\\NT-AUTORITÄT\\SYSTEM\\MFilesLog\\Event-Log 23.10.2020 09-05.xml', SINGLE_BLOB) AS Products(P)";
command += "SELECT @x";
command += "DECLARE @hdoc int";
command += "EXEC sp_xml_preparedocument @hdoc, OUTPUT, @x";
command += "INSERT INTO [MFlogs].[dbo].[MLogs]";
command += "SELECT * FROM OPENXML(@hdoc, '/Export/root/event/data/objectversion/objver', 2);";
command += "WITH(";
command += "id int '../../../id',";
command += "type varchar(50) '../../../type',";
command += "category varchar(50) '../../../category',";
command += "timestamp varchar(50) '../../../timestamp',";
command += "causedbyuser varchar(50) '../../../causedbyuser',";
command += "objtype varchar(50),";
command += "objid varchar(50),";
command += "version varchar(50),";
command += "objectguid varchar(50) '../objectguid',";
command += "versionguid varchar(50) '../versionguid',";
command += "title varchar(100) '../title',";
command += "displayid int '../displayid')";
SqlCommand cmd = new SqlCommand(command, connection);
int result = cmd.ExecuteNonQuery();
This is the error from the event log:
The @ hdoc scalar variable must be declared.
Can someone help?
command.