【问题标题】:Data not inserting into Azure Sql database数据未插入 Azure Sql 数据库
【发布时间】:2015-07-11 00:23:20
【问题描述】:

这是我第一次使用 Azure,但遇到了问题。

我的 MVC 项目中有一个注册和登录脚本,它在我的本地计算机上运行良好,但是当我尝试使用 Azure 时,我在“处理您的请求时发生错误”页面上收到此消息。

我已在防火墙中允许该 IP。 我已将数据库与网站链接。

该项目使用代码优先模型。当我尝试注册时,它将在数据库中创建表,但不会输入用户数据。所以我只剩下一张空桌子。

此外,当我尝试从 Sql management studio 部署我的数据库时,它会创建表但无法输入数据。

我做错了什么?

编辑:

所以当我尝试从 SQL Management Studio 部署我的数据库时,这是我在导入数据库时​​遇到的错误

TITLE: Microsoft SQL Server Management Studio
------------------------------

Could not import package.
Warning SQL0: A project which specifies SQL Server 2012 as the target platform may experience compatibility issues with SQL Azure.
Error SQL72014: .Net SqlClient Data Provider: Msg 40511, Level 15, State 1, Line 2 Built-in function 'newsequentialid' is not supported in this version of SQL Server.
Error SQL72045: Script execution error.  The executed script:
ALTER TABLE [dbo].[Domains]
    ADD DEFAULT (newsequentialid()) FOR [DomainId];


 (Microsoft.SqlServer.Dac)

我认为这是由于我的模型使用了 GUID。这可能是导致 Azure 上的数据库出现所有这些问题的原因吗?

【问题讨论】:

  • 当您尝试插入或创建某些内容时,您会收到什么错误消息?
  • 显示一些代码,雅各布。
  • 我不确定要向您展示什么代码,因为我刚刚意识到任何需要数据库进行用户登录或其他原因的页面都会导致An error occurred while processing your request.。一切都可以在本地运行,但不能在 Azure 上运行。
  • 只需谷歌搜索“newsequentialid azure”就会提示您应该为您的DomainId 列切换到uniqueidentifier/newid()

标签: c# sql asp.net-mvc azure azure-sql-database


【解决方案1】:

错误消息几乎描述了您的问题:

Warning SQL0: A project which specifies SQL Server 2012 as the target platform may
              experience compatibility issues with SQL Azure.
Error SQL72014: .Net SqlClient Data Provider: Msg 40511, Level 15, State 1, Line 2 
                Built-in function 'newsequentialid' is not supported in this version of SQL Server.

SQL Server 和 Azure SQL 是not 100% feature compatible(甚至差距也在迅速缩小):

目前,Azure SQL 数据库不支持 SQL Server 的所有功能。有关详细的比较信息,请参阅 Azure SQL 数据库指南和限制。当您想要将现有数据库移动到 Azure SQL 数据库时请注意这一点,因为您可能需要一些额外的数据库重新设计预算。

所以您的问题是您使用了不受支持的功能newsequentialid

【讨论】:

    【解决方案2】:

    上周晚些时候,Azure 推出了 Azure SQL DB 最新版本的预览版,在该预览版中,现在支持 NewSequentialID 以及许多以前不可用的其他功能。

    要使用最新版本创建数据库,请使用新门户 portal.azure.com,并按照屏幕上的指导在创建新 Azure 数据库时使用预览版。

    【讨论】:

    • 我已经尝试过了,但是当我点击新版本时它只是重定向到微软的主页。
    • 如果您尝试此页面上的 SQL 数据库更新预览链接,它对您有用吗:azure.microsoft.com/en-us/services/preview
    【解决方案3】:

    简短的回答是,如果您只需要一个独特的 Guid,只需将所有 newsequentialid() 更改为 newid()

    这是一篇很好的参考博文Uniqueidentifier and Clustered Indexes,由 Microsoft Azure 团队发布。

    newsequentialid()的部分,描述了区别:

    如果 NEWID() 函数生成唯一的非序列 uniqueidentifier 比 NEWSEQUENTIALID() 函数生成唯一 顺序唯一标识符。 NEWSEQUENTIALID() 的唯一技巧 功能是GUID是部分基于网络生成的 电脑卡。

    此外,newsequentialid() 甚至不推荐,因为

    (i)t 可以猜测下一个生成的 GUID 的值,并且, 因此,访问与该 GUID 关联的数据。

    【讨论】:

      【解决方案4】:

      如果没有任何代码,很难说出发生了什么,但很可能您忘记了将条目提交到表中。 SqlCommand.Dispose() before SqlTransaction.Commit()? 可能会对你有所帮助。

      【讨论】:

        猜你喜欢
        • 2011-01-29
        • 1970-01-01
        • 2019-09-11
        • 1970-01-01
        • 1970-01-01
        • 2023-04-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多