如何重新分发aspnet_regsql.exe?

时间:2009-02-24 10:23:42

标签: asp.net

我正在为我的ASP.NET网站编写一个安装程序,我需要使用aspnet_regsql工具来注册/取消注册成员资格/角色表到我的数据库中。

如果我将其与我的设置捆绑在一起,那么我需要包含哪些相关文件才能确保一切正常?

或者最好不捆绑它,但是在运行时找到.NET Framework文件夹并从那里启动它?

3 个答案:

答案 0 :(得分:1)

您不应该分发它,您应该使用在适当的框架运行时中找到它并从那里使用它。

可能SP和修补程序补丁可能会稍微修改该文件,以适应其所属框架的其他调整。如果在发行版中包含版本,则可能与客户端计算机上的框架修订版不同步。

好的,在这种情况下实际上不太可能,但最好不要重新分配应该在预安装框架中的内容。

答案 1 :(得分:1)

最好不要捆绑它,而是找到.NET Framework文件夹并启动它。请参阅How do I get .NET Framework directory以了解它。

答案 2 :(得分:1)

使用我们值得信赖的朋友Reflector,它引用:

  • mscorlib程序
  • 系统
  • System.Data
  • System.Drawing中
  • 的System.Web
  • System.Windows.Forms的
  • ADVAPI32.DLL
  • KERNEL32.DLL

没有什么特别的,只有.NET框架。我的.exe位于

C:\Windows\winsxs\x86_aspnet_regsql_b03f5f7f11d50a3a_6.0.6000.16720_none_50001be1bbe18d26

因此从框架目录启动可能不起作用(或者我的机器有一个奇怪的安装)。

这是它引用的表,来自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";