0

I have a database on SQL Azure which has an identity primary. After using SQL Server Import and Export Wizard, I transferred the data to my SQL Server 2008 R2 database.

My ASP.NET Application runs fine and reads the data. But When I try to insert a value in a table 'User', it gives me an error: Cannot insert null in column 'UserId'.

The reason being that it is not able to generate the identity value.

How can I overcome this issue?

PS: I tried Generating the scripts from SQL Azure, but the SQL file is 500MB in size and my host does not allow that big a script to run.

Edit: using Entity Framework for data access. The UserId field has an IDENTITY property (1,1).

Edit Tried to create the schema from SQLAzure Migration tool and then used the import/export data to copy the data. But the wizard does not maintain the relations amongst the rows.

4

2 回答 2

0

数据导入/导出向导不会保留数据库对象的整个结构。

即它只会复制数据,而不是数据适合的表的整个结构 - 包括身份和密钥定义。

您可以导入数据,然后手动设置所有主键和默认字段以匹配您所需的数据库定义,或者您可以连接到您的 Azure 实例并使用生成脚本选项在复制之前在 2008 数据库中生成您的架构。

但真正的答案是,您应该使用复制数据库向导来完成此操作,它适用于 Azure。它是为这种情况而设计的。

于 2013-03-19T13:45:58.510 回答
0

问题是向导试图插入主键值,默认情况下禁用。如果不插入主键,则无法维护关系,因此整个问题。

要解决此问题并进行万无一失的迁移,请确保新架构维护所有标识列。

选择源表和目标表时,对于特定表,单击“编辑映射”并选中“启用标识插入”复选框以启用主键值的插入,从而保持结构和关系不变。

于 2014-02-03T19:47:17.150 回答