将Microsoft Access数据库迁移到SQL Server Compact Edtion 4.0

时间:2016-02-11 17:02:35

标签: database ms-access migration sql-server-ce database-migration

我创建了一个使用Microsoft Access数据库的应用程序,我遇到了一些问题,因此希望迁移到Microsoft SQL Server Compact Edition。

我已经研究过几个工具,但是我找不到任何可以将Access数据库转换为SQL CE的东西。有没有人建议快速重新创建表格或链接到我可以使用的软件工具?理想情况下是免费解决方案,还是相当便宜(> 50英镑?)

我试过了:

  • Microsoft SSMA - 此工具支持除紧凑版之外的每个SQL Server版本。
  • Primeworks - 下载该工具的链接现已停止

2 个答案:

答案 0 :(得分:2)

1:使用font-awesome从Access迁移到免费的SQL Server版本(LocalDB / Express)

2:在Visual Studio 2015社区版(也是免费的)中,使用我的免费“SSMA”从SQL Server数据库迁移到SQL Compact(通过“一键式”或通过脚本)

答案 1 :(得分:1)

正如我在上面的评论中所说,我必须记住我之前是如何做到的。

我使用(现在仍然)SQL Server Express Edition,它是免费下载的。我不确定它与您所指的Compact Edition之间的区别。我也不确定你的约束是什么,所以这可能不适合你但是......

步骤1)安装SQL Server Express和SQL Server Management Studio。它采用单一包装。我认为你必须得到一个Microsoft帐户才能下载它

步骤2)创建一个新数据库,将您的访问数据库导入

步骤3)在这个新数据库中选择任务/导入数据

步骤4)选择Access作为源(选择文件),目标SQL Server Native Client(并选择您所在的数据库)

步骤5)整理。我必须创建并运行一些脚本来复制表,将Autonum主键设置为正确的值等。最后,我创建了几个存储过程来帮助我。

这是一个。我无法记住细节,所以请按照您的意愿

-- =============================================
-- Author:      Alan Chandler
-- Create date: 10th May 2011
-- Description: Migrates a single table (passed as a parameter) to database
-- =============================================
CREATE PROCEDURE [dbo].[MigrateTable] 
    -- Add the parameters for the stored procedure here
    @table_name sysname
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
    SET @table_name = RTRIM(@table_name)
    DECLARE @cmd AS NVARCHAR(max)
    DECLARE @column_name AS NVARCHAR(max)
    DECLARE @object_id AS int
    DECLARE @has_identity AS int
    DECLARE @comma_needed AS bit
    DECLARE column_list_cursor CURSOR READ_ONLY FOR
        SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = @table_name ;

    -- Insert statements for procedure here
    -- Do Complete Process as a transaction in case it goes wrong
    BEGIN TRANSACTION
    SELECT @object_id = OBJECT_ID(QUOTENAME(@Table_name))
    SELECT @has_identity = ISNULL(OBJECTPROPERTY(@object_id,'TableHasIdentity'),0)
    SET @cmd = N'DELETE FROM '+QUOTENAME(@table_name)
    EXEC sp_executesql @cmd
    SET @cmd = N'';
    IF @has_identity > 0 
    BEGIN
        -- If We Have an Identity Column we need to allow the insertion without thinking about it
        SET @cmd = N'SET IDENTITY_INSERT '+QUOTENAME(@table_name)+N' ON;'
    END
    -- Create an Insert Statement ...
    SET @cmd = @cmd+N'INSERT INTO [dbo].'+QUOTENAME(@table_name)+N' (';
    -- ... Listing all the column names
    OPEN column_list_cursor;
    SET @comma_needed = N'FALSE'
    FETCH NEXT FROM column_list_cursor INTO @Column_name
    WHILE @@FETCH_STATUS = 0
    BEGIN
        IF @comma_needed = N'TRUE' SET @cmd = @cmd + N',';
        SET @cmd = @cmd + QUOTENAME(@Column_name)
        SET @comma_needed = N'TRUE';
        FETCH NEXT FROM column_list_cursor INTO @Column_name
    END
    SET @cmd = @cmd+N') SELECT '
    -- Now start to create the Select Statement from the other database ...
    SET @comma_needed = N'FALSE'
    CLOSE column_list_cursor;
    -- ... again listing all the column names
    OPEN column_list_cursor;
    FETCH NEXT FROM column_list_cursor INTO @Column_name
    WHILE @@FETCH_STATUS = 0
    BEGIN
        IF @comma_needed = N'TRUE' SET @cmd = @cmd + N',';
        SET @cmd = @cmd + QUOTENAME(@Column_name)
        SET @comma_needed = N'TRUE';
        FETCH NEXT FROM column_list_cursor INTO @Column_name
    END
    CLOSE column_list_cursor
    DEALLOCATE column_list_cursor
    SET @cmd = @cmd + N' FROM [Accuvision].[dbo].'+QUOTENAME(@table_name)+N';'
    IF @has_identity > 0 
    BEGIN
        -- Switch identity function back on and reseed the value
        SET @cmd = @cmd+N'SET IDENTITY_INSERT '+QUOTENAME(@table_name)+N' OFF;'
        SET @cmd = @cmd+N'DBCC CHECKIDENT ('+QUOTENAME(@table_name)+N',RESEED)'
    END
    EXEC sp_executesql @cmd
    COMMIT
    PRINT N'Migration of '+QUOTENAME(@table_name)+N' complete'
END

这是从第二个程序调用的。我无法发布所有内容,因为我所做的清理工作是保密的,但通用位是遵循......

-- =============================================
-- Author:      Alan Chandler
-- Create date: 10th May 2011
-- Description: Migrates Accuvision Database (itself imported
--              from an access database of the same name) into
--              the current database, avoiding IDENTITY ISSUES
-- =============================================
CREATE PROCEDURE [dbo].[Migrate] 
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
    DECLARE @Table_Name nvarchar(max);
    DECLARE table_list_cursor CURSOR FORWARD_ONLY READ_ONLY FOR
        SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = N'BASE TABLE';
    -- Turn off contraint checking on all tables
    EXEC sp_MSforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"

    OPEN table_list_cursor;
    FETCH NEXT FROM table_list_cursor INTO @Table_name
    WHILE @@FETCH_STATUS = 0
    BEGIN
        IF @Table_Name NOT IN ( N'WebSiteLeads', N'Debug_Log', N'Config',N'People',N'UserLog',N'ProcedureType',N'DailyDates',N'Locks',N'CallLog')
            EXEC [dbo].[MigrateTable] @Table_name
        FETCH NEXT FROM table_list_cursor INTO @Table_name
    END
    CLOSE table_list_cursor;
    DEALLOCATE table_list_cursor;

--- Lots of calls to 
    SET IDENTITY_INSERT [XXXX] ON;
-- do stuff to table
    SET IDENTITY_INSERT [XXXX] OFF;
    DBCC CHECKIDENT ('XXXX',RESEED)
--
    PRINT N'Last Step, resetting constraints'
    EXEC sp_msForEachTable "ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all"  
    PRINT N'DATA MIGRATION COMPLETE'    
END

我希望能帮到你。对不起,如果没有,但正如你可以看到它近5年前我创建了这些程序 - 使用它们几次直到它全部工作,我迁移了数据库,直到刚才再也没有看过它们

如果您遇到安全问题,请参阅 https://www.chandlerfamily.org.uk/2011/04/importing-access-database-into-sqlserver-when-the-former-is-protected-with-a-workgroup-file/

如果你想要一些备份程序等我把它们放在这里 https://www.chandlerfamily.org.uk/2011/05/an-automated-backup-regime-for-a-small-sql-server-database/