Hello,
I am trying to put a few lines in an SalDataProvider. This works perfectly when I run it in a QUERY inside SQL Management Studio.
if col_length('dbo.VGN_SOAPBOX_SETTINGS', 'NAMETYPE') is null
ALTER TABLE VGN_SOAPBOX_SETTINGS ADD
[NAMETYPE] [int] NULL
UPDATE VGN_SOAPBOX_SETTINGS
SET [NAMETYPE] = 0 WHERE [NAMETYPE] IS NULL
It executes just fine. But when I run it in DNN as a script in the SQL section, I always get...
System.Data.SqlClient.SqlException: Invalid column name 'NAMETYPE'. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at DotNetNuke.Data.SqlDataProvider.ExecuteADOScript(String SQL) at DotNetNuke.Data.SqlDataProvider.ExecuteScript(String Script, Boolean UseTransactions) if col_length('dbo.VGN_SOAPBOX_SETTINGS', 'NAMETYPE') is null ALTER TABLE VGN_SOAPBOX_SETTINGS ADD [NAMETYPE] [int] NULL UPDATE VGN_SOAPBOX_SETTINGS SET [NAMETYPE] = 0 WHERE [NAMETYPE] IS NULL
I have tried numerous ways to test if the column is there, and I always get the same sort of error. I just want to test for the column and then execute if it doesn't exist. Why doesn't this work when I run it in DNN, but does work in SQL Management Studio? Or can someone tell me how to test for a column in DNN that WILL work? Thanks.