tags:

views:

133

answers:

3

I am writing a setup program for my ASP.NET web site, and I need to incorporate the aspnet_regsql tool for registering/unregistering the membership/roles tables into my database.

If I bundle this with my setup, what are all the dependent files I need to include to ensure it all works?

Or is it better to not bundle this, but locate the .NET Framework folder at runtime and launch it from there?

+1  A: 

You should not distribute it, you should use find it in the appropriate framework runtime and use it from there.

It could be that SPs and hotfix patches may modify the file slightly to be appropriate to other tweaks to the framework to which it belongs. If you include a version in your distribution it may be out of sync with the revision of the framework on the client machine.

Ok thats actually unlikely in this case but still its better not to redistribute something which ought be in the preinstalled framework.

AnthonyWJones
+1  A: 

It is better not to bundle it, rather locate the .NET Framework folder and launch it. See How do I get .NET Framework directory for figuring it out.

Robert MacLean
+1  A: 

Using our trusty friend Reflector, it references:

  • mscorlib
  • System
  • System.Data
  • System.Drawing
  • System.Web
  • System.Windows.Forms
  • advapi32.dll
  • kernel32.dll

So nothing extraordinary, just the .NET framework. My .exe is found in

C:\Windows\winsxs\x86_aspnet_regsql_b03f5f7f11d50a3a_6.0.6000.16720_none_50001be1bbe18d26

so launching from the framework directory might not work (or my machine has a strange install).

Here's the tables it references, from SqlCacheDependencyAdmin

internal const string SQL_CREATE_ENABLE_DATABASE_SP = "/* Create notification table */ \nIF NOT EXISTS (SELECT name FROM sysobjects WITH (NOLOCK) WHERE name = '{0}' AND type = 'U') \n   IF NOT EXISTS (SELECT name FROM sysobjects WITH (TABLOCKX) WHERE name = '{0}' AND type = 'U') \n      CREATE TABLE dbo.{0} (\n      tableName             NVARCHAR(450) NOT NULL PRIMARY KEY,\n      notificationCreated   DATETIME NOT NULL DEFAULT(GETDATE()),\n      changeId              INT NOT NULL DEFAULT(0)\n      )\n\n/* Create polling SP */\nIF NOT EXISTS (SELECT name FROM sysobjects WITH (NOLOCK) WHERE name = '{1}' AND type = 'P') \n   IF NOT EXISTS (SELECT name FROM sysobjects WITH (TABLOCKX) WHERE name = '{1}' AND type = 'P') \n   EXEC('CREATE PROCEDURE dbo.{1} AS\n         SELECT tableName, changeId FROM dbo.{0}\n         RETURN 0')\n\n/* Create SP for registering a table. */ \nIF NOT EXISTS (SELECT name FROM sysobjects WITH (NOLOCK) WHERE name = '{2}' AND type = 'P') \n   IF NOT EXISTS (SELECT name FROM sysobjects WITH (TABLOCKX) WHERE name = '{2}' AND type = 'P') \n   EXEC('CREATE PROCEDURE dbo.{2} \n             @tableName NVARCHAR(450) \n         AS\n         BEGIN\n\n         DECLARE @triggerName AS NVARCHAR(3000) \n         DECLARE @fullTriggerName AS NVARCHAR(3000)\n         DECLARE @canonTableName NVARCHAR(3000) \n         DECLARE @quotedTableName NVARCHAR(3000) \n\n         /* Create the trigger name */ \n         SET @triggerName = REPLACE(@tableName, ''['', ''__o__'') \n         SET @triggerName = REPLACE(@triggerName, '']'', ''__c__'') \n         SET @triggerName = @triggerName + ''{3}'' \n         SET @fullTriggerName = ''dbo.['' + @triggerName + '']'' \n\n         /* Create the cannonicalized table name for trigger creation */ \n         /* Do not touch it if the name contains other delimiters */ \n         IF (CHARINDEX(''.'', @tableName) <> 0 OR \n             CHARINDEX(''['', @tableName) <> 0 OR \n             CHARINDEX('']'', @tableName) <> 0) \n             SET @canonTableName = @tableName \n         ELSE \n             SET @canonTableName = ''['' + @tableName + '']'' \n\n         /* First make sure the table exists */ \n         IF (SELECT OBJECT_ID(@tableName, ''U'')) IS NULL \n         BEGIN \n             RAISERROR (''00000001'', 16, 1) \n             RETURN \n         END \n\n         BEGIN TRAN\n         /* Insert the value into the notification table */ \n         IF NOT EXISTS (SELECT tableName FROM dbo.{0} WITH (NOLOCK) WHERE tableName = @tableName) \n             IF NOT EXISTS (SELECT tableName FROM dbo.{0} WITH (TABLOCKX) WHERE tableName = @tableName) \n                 INSERT  dbo.{0} \n                 VALUES (@tableName, GETDATE(), 0)\n\n         /* Create the trigger */ \n         SET @quotedTableName = QUOTENAME(@tableName, '''''''') \n         IF NOT EXISTS (SELECT name FROM sysobjects WITH (NOLOCK) WHERE name = @triggerName AND type = ''TR'') \n             IF NOT EXISTS (SELECT name FROM sysobjects WITH (TABLOCKX) WHERE name = @triggerName AND type = ''TR'') \n                 EXEC(''CREATE TRIGGER '' + @fullTriggerName + '' ON '' + @canonTableName +''\n                       FOR INSERT, UPDATE, DELETE AS BEGIN\n                       SET NOCOUNT ON\n                       EXEC dbo.{6} N'' + @quotedTableName + ''\n                       END\n                       '')\n         COMMIT TRAN\n         END\n   ')\n\n/* Create SP for updating the change Id of a table. */ \nIF NOT EXISTS (SELECT name FROM sysobjects WITH (NOLOCK) WHERE name = '{6}' AND type = 'P') \n   IF NOT EXISTS (SELECT name FROM sysobjects WITH (TABLOCKX) WHERE name = '{6}' AND type = 'P') \n   EXEC('CREATE PROCEDURE dbo.{6} \n             @tableName NVARCHAR(450) \n         AS\n\n         BEGIN \n             UPDATE dbo.{0} WITH (ROWLOCK) SET changeId = changeId + 1 \n             WHERE tableName = @tableName\n         END\n   ')\n\n/* Create SP for unregistering a table. */ \nIF NOT EXISTS (SELECT name FROM sysobjects WITH (NOLOCK) WHERE name = '{4}' AND type = 'P') \n   IF NOT EXISTS (SELECT name FROM sysobjects WITH (TABLOCKX) WHERE name = '{4}' AND type = 'P') \n   EXEC('CREATE PROCEDURE dbo.{4} \n             @tableName NVARCHAR(450) \n         AS\n         BEGIN\n\n         BEGIN TRAN\n         DECLARE @triggerName AS NVARCHAR(3000) \n         DECLARE @fullTriggerName AS NVARCHAR(3000)\n         SET @triggerName = REPLACE(@tableName, ''['', ''__o__'') \n         SET @triggerName = REPLACE(@triggerName, '']'', ''__c__'') \n         SET @triggerName = @triggerName + ''{3}'' \n         SET @fullTriggerName = ''dbo.['' + @triggerName + '']'' \n\n         /* Remove the table-row from the notification table */ \n         IF EXISTS (SELECT name FROM sysobjects WITH (NOLOCK) WHERE name = ''{0}'' AND type = ''U'') \n             IF EXISTS (SELECT name FROM sysobjects WITH (TABLOCKX) WHERE name = ''{0}'' AND type = ''U'') \n             DELETE FROM dbo.{0} WHERE tableName = @tableName \n\n         /* Remove the trigger */ \n         IF EXISTS (SELECT name FROM sysobjects WITH (NOLOCK) WHERE name = @triggerName AND type = ''TR'') \n             IF EXISTS (SELECT name FROM sysobjects WITH (TABLOCKX) WHERE name = @triggerName AND type = ''TR'') \n             EXEC(''DROP TRIGGER '' + @fullTriggerName) \n\n         COMMIT TRAN\n         END\n   ')\n\n/* Create SP for querying all registered table */ \nIF NOT EXISTS (SELECT name FROM sysobjects WITH (NOLOCK) WHERE name = '{5}' AND type = 'P') \n   IF NOT EXISTS (SELECT name FROM sysobjects WITH (TABLOCKX) WHERE name = '{5}' AND type = 'P') \n   EXEC('CREATE PROCEDURE dbo.{5} \n         AS\n         SELECT tableName FROM dbo.{0}   ')\n\n/* Create roles and grant them access to SP  */ \nIF NOT EXISTS (SELECT name FROM sysusers WHERE issqlrole = 1 AND name = N'aspnet_ChangeNotification_ReceiveNotificationsOnlyAccess') \n    EXEC sp_addrole N'aspnet_ChangeNotification_ReceiveNotificationsOnlyAccess' \n\nGRANT EXECUTE ON dbo.{1} to aspnet_ChangeNotification_ReceiveNotificationsOnlyAccess\n\n";
    internal const string SQL_DISABLE_DATABASE = "/* Remove notification table */ \nIF EXISTS (SELECT name FROM sysobjects WITH (NOLOCK) WHERE name = '{0}' AND type = 'U') \n    IF EXISTS (SELECT name FROM sysobjects WITH (TABLOCKX) WHERE name = '{0}' AND type = 'U') \n    BEGIN\n      /* First, unregister all registered tables */ \n      DECLARE tables_cursor CURSOR FOR \n      SELECT tableName FROM dbo.{0} \n      DECLARE @tableName AS NVARCHAR(450) \n\n      OPEN tables_cursor \n\n      /* Perform the first fetch. */ \n      FETCH NEXT FROM tables_cursor INTO @tableName \n\n      /* Check @@FETCH_STATUS to see if there are any more rows to fetch. */ \n      WHILE @@FETCH_STATUS = 0 \n      BEGIN \n          EXEC {3} @tableName \n\n          /* This is executed as long as the previous fetch succeeds. */ \n          FETCH NEXT FROM tables_cursor INTO @tableName \n      END \n      CLOSE tables_cursor \n      DEALLOCATE tables_cursor \n\n      /* Drop the table */\n      DROP TABLE dbo.{0} \n    END\n\n/* Remove polling SP */ \nIF EXISTS (SELECT name FROM sysobjects WITH (NOLOCK) WHERE name = '{1}' AND type = 'P') \n    IF EXISTS (SELECT name FROM sysobjects WITH (TABLOCKX) WHERE name = '{1}' AND type = 'P') \n      DROP PROCEDURE dbo.{1} \n\n/* Remove SP that registers a table */ \nIF EXISTS (SELECT name FROM sysobjects WITH (NOLOCK) WHERE name = '{2}' AND type = 'P') \n    IF EXISTS (SELECT name FROM sysobjects WITH (TABLOCKX) WHERE name = '{2}' AND type = 'P') \n      DROP PROCEDURE dbo.{2} \n\n/* Remove SP that unregisters a table */ \nIF EXISTS (SELECT name FROM sysobjects WITH (NOLOCK) WHERE name = '{3}' AND type = 'P') \n    IF EXISTS (SELECT name FROM sysobjects WITH (TABLOCKX) WHERE name = '{3}' AND type = 'P') \n      DROP PROCEDURE dbo.{3} \n\n/* Remove SP that querys the registered table */ \nIF EXISTS (SELECT name FROM sysobjects WITH (NOLOCK) WHERE name = '{4}' AND type = 'P') \n    IF EXISTS (SELECT name FROM sysobjects WITH (TABLOCKX) WHERE name = '{4}' AND type = 'P') \n      DROP PROCEDURE dbo.{4} \n\n/* Remove SP that updates the change Id of a table. */ \nIF EXISTS (SELECT name FROM sysobjects WITH (NOLOCK) WHERE name = '{5}' AND type = 'P') \n    IF EXISTS (SELECT name FROM sysobjects WITH (TABLOCKX) WHERE name = '{5}' AND type = 'P') \n      DROP PROCEDURE dbo.{5} \n\n/* Drop roles */ \nIF EXISTS ( SELECT name FROM sysusers WHERE issqlrole = 1 AND name = 'aspnet_ChangeNotification_ReceiveNotificationsOnlyAccess') BEGIN\nCREATE TABLE #aspnet_RoleMembers \n( \n    Group_name      sysname, \n    Group_id        smallint, \n    Users_in_group  sysname, \n    User_id         smallint \n) \nINSERT INTO #aspnet_RoleMembers \nEXEC sp_helpuser 'aspnet_ChangeNotification_ReceiveNotificationsOnlyAccess' \n \nDECLARE @user_id smallint \nDECLARE @cmd nvarchar(500) \nDECLARE c1 CURSOR FORWARD_ONLY FOR  \n    SELECT User_id FROM #aspnet_RoleMembers \n  \nOPEN c1 \n  \nFETCH c1 INTO @user_id \nWHILE (@@fetch_status = 0)  \nBEGIN \n    SET @cmd = 'EXEC sp_droprolemember ''aspnet_ChangeNotification_ReceiveNotificationsOnlyAccess'',''' + USER_NAME(@user_id) + '''' \n    EXEC (@cmd) \n    FETCH c1 INTO @user_id \nEND \n \nclose c1 \ndeallocate c1 \n    EXEC sp_droprole 'aspnet_ChangeNotification_ReceiveNotificationsOnlyAccess'\nEND\n";
    internal const string SQL_QUERY_REGISTERED_TABLES_SP = "AspNet_SqlCacheQueryRegisteredTablesStoredProcedure";
    internal const string SQL_QUERY_REGISTERED_TABLES_SP_DBO = "dbo.AspNet_SqlCacheQueryRegisteredTablesStoredProcedure";
    internal const string SQL_REGISTER_TABLE_SP = "AspNet_SqlCacheRegisterTableStoredProcedure";
    internal const string SQL_REGISTER_TABLE_SP_DBO = "dbo.AspNet_SqlCacheRegisterTableStoredProcedure";
    internal const string SQL_TRIGGER_NAME_POSTFIX = "_AspNet_SqlCacheNotification_Trigger";
    internal const string SQL_UNREGISTER_TABLE_SP = "AspNet_SqlCacheUnRegisterTableStoredProcedure";
    internal const string SQL_UNREGISTER_TABLE_SP_DBO = "dbo.AspNet_SqlCacheUnRegisterTableStoredProcedure";
    internal const string SQL_UPDATE_CHANGE_ID_SP = "AspNet_SqlCacheUpdateChangeIdStoredProcedure";
Chris S
Thanks but I was also concerned about whether it referenced some SQL scripts... there are a bunch of them in the framework directory.
DSO
As far as I can tell the application just references resource strings and constants from SqlCacheDependencyAdmin
Chris S