I’m using C# for a custom action in wix, which works fine. The custom action essentially just runs sql scripts based on the parameters passed to a method.
One of the scripts I’m running populates one of my tables with data, if there’s nothing in it, and looks something like this:
IF (SELECT COUNT(*) FROM [dbo].[Table]) = 0
BEGIN
INSERT [dbo].[Table] ([ItemId], [Description]) VALUES (N'<<GUID>>', NULL)
INSERT [dbo].[Table] ([ItemId], [Description]) VALUES (N'<<GUID>>', N'The 2nd Item')
...
END
In this instance <<GUID>> is something like e00104e4-7e5f-4563-9356-30732d5ca57e – these scripts were generated from data exports of SQL Server 2008 R2 using the corresponding edition of Management Studio.
When I run this script in Management Studio, it works fine and as expected, all the data gets inserted if there is nothing already there. Running it via the C# code, however, and I get the following exception:
Conversion failed when converting from a character string to uniqueidentifier
As the only uniqueidentifier column in the table, this has to be the ItemId column, but I can’t figure out why this is happening, or how to resolve the issue, and the last hour searching online hasn’t given anything either.
EDIT
I should add that these SQL queries are located in a file, which the C# code then reads the content of as the SQL query. I don’t really want to have to modify them if I can help it, as it adds an extra step that shouldn’t be needed.
I’ve resolved the issue now. Turns out that one of the scripts was out of date, and the ID of that table had been changed from an
nvarcharto auniqueidentifier.2 things then happened, the first was that nobody else updated the script that populated that tables default data. The 2nd was that wix (or the custom action running the SQL, I’m not sure exactly which) was reporting the error after the first script, which happens to have a very similar table structure.
So, in all, I should’ve spotted what the issue was sooner. Instead, I get to have made a fool out of myself on SA for not doing so. Thanks for the answers anyway, hopefully they’ll be of use to someone who stumbles across this question.