简体   繁体   English

使用Azure数据库(ASP.NET MVC)

[英]Use Azure Database (ASP.NET MVC)

I'm new in ASP.NET Development 我是ASP.NET开发的新手

I create MVC Project and as I understood it creates with default .mdf database. 我创建了MVC项目,据我所知,它是使用默认的.mdf数据库创建的。

I working with it and all was great, but I think about deploying app to azure. 我使用它,一切都很棒,但是我考虑将应用程序部署到天蓝色。

So I need to use azure database. 所以我需要使用azure数据库。

I create it , all ok. 我创建了,一切正常。

I read article how connect to azure db. 我读了文章如何连接到Azure数据库。

As I understood , I need connection string 据我了解,我需要连接字符串

Here it is 这里是

Server=tcp:smartsolutionsserver.database.windows.net,1433;Initial Catalog=smartdatabase;Persist Security Info=False;User ID={your_username};Password={your_password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;

As I understood I need to paste it to Web.Release.config 据我了解,我需要将其粘贴到Web.Release.config

I do this, so now it have look like this 我这样做,所以现在看起来像这样

 <connectionStrings>
  <add name="DefaultConnection"
    connectionString="Server=tcp:smartsolutionsserver.database.windows.net,1433;Initial Catalog=smartdatabase;Persist Security Info=False;User ID=*********;Password=******;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
    xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>

But as I understood .mdf database connections wrote in Web.config file 但是据我了解,.mdf数据库连接写在Web.config文件中

And looks like this 看起来像这样

<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-SmartSolutions-20170124034333.mdf;Initial Catalog=aspnet-SmartSolutions-20170124034333;Integrated Security=True" providerName="System.Data.SqlClient" />

Tell me, how I can connect to azure database and use it instead of local .mdf database? 告诉我,如何连接到Azure数据库并使用它代替本地.mdf数据库?

Thank's so much for help. 非常感谢您的帮助。

UPDATE UPDATE

I try to add 2 new tables and publish app. 我尝试添加2个新表并发布应用。 After connecting to database from SQL Server Object Explorer, I see that tables added. 从SQL Server对象资源管理器连接到数据库后,我看到添加了这些表。

But when I try to register new user I see this 但是当我尝试注册新用户时,我看到了

On local all ok 在当地都可以

Screen 屏幕

So my error was in The model backing the 'ApplicationDbContext' context has changed since the database was created 所以我的错误是The model backing the 'ApplicationDbContext' context has changed since the database was created

I go to table __MigrationHistory and delete row. 我转到表__MigrationHistory并删除行。 After that, all okay. 之后,一切都很好。 All works 全部作品

@ juunas Thank's for advice. @ juunas谢谢您的建议。 I do this and see error. 我这样做,看到错误。 Also it can visible if you use IIS Console 如果您使用IIS控制台,它也会可见

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM