update the database from package manager console in code ...
文章推薦指數: 80 %
I'm trying to update the database from package Manager console.If my Domain class change, I have to drop and create the database,Instead of dropping the ...
Home
Public
Questions
Tags
Users
Companies
Collectives
ExploreCollectives
Teams
StackOverflowforTeams
–Startcollaboratingandsharingorganizationalknowledge.
CreateafreeTeam
WhyTeams?
Teams
CreatefreeTeam
Collectives™onStackOverflow
Findcentralized,trustedcontentandcollaboratearoundthetechnologiesyouusemost.
LearnmoreaboutCollectives
Teams
Q&Aforwork
Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch.
LearnmoreaboutTeams
updatethedatabasefrompackagemanagerconsoleincodefirstenvironment
AskQuestion
Asked
7years,1monthago
Modified
4years,3monthsago
Viewed
103ktimes
31
CodeFirstEnvironment
I'mtryingtoupdatethedatabasefrompackageManagerconsole.IfmyDomainclasschange,Ihavetodropandcreatethedatabase,InsteadofdroppingtheDatabasehowcaniupdatethedatabase.
Ihavealreadytrybyreadingsomeblogsingoogle.
commands
PM>Install-PackageEntityFramework
ByusingthiscommandiinstalltheEntityFrameworksuccessfully.
PM>Enable-Migrations
ByusingthiscommanditcreatedtheMigrationfileinmyproject.
PM>Update-Database
Byusingthiscommand,imayupdatethetablebutihaveaProblemhere.
Error
Specifythe'-Verbose'flagtoviewtheSQLstatementsbeingappliedtothetargetdatabase.
System.Data.SqlClient.SqlException(0x80131904):Anetwork-relatedorinstance-specificerroroccurredwhileestablishingaconnectiontoSQLServer.Theserverwasnotfoundorwasnotaccessible.VerifythattheinstancenameiscorrectandthatSQLServerisconfiguredtoallowremoteconnections.
Doubtishere
SometimesItmayupdateifonlyonefieldchangesinPOCOClass.ForexampleIhaveUpdatedthemorenumberofDomainclass,HowcaniUpdatetheDatabasefromPackagemanagerConsole.AnyIdea?
c#sql-servervisual-studio-2012entity-framework-6entity-framework-migrations
Share
Improvethisquestion
Follow
editedJun20,2020at9:12
CommunityBot
111silverbadge
askedAug25,2015at4:50
vinodhvinodh
68411goldbadge77silverbadges2020bronzebadges
2
1
Asitstates,youcannotconnect.CheckifSQLServerisrunningandyouhavecorrectconnectionstring.
– LukaszSzozda
Aug25,2015at4:51
IhaveaddedtheconnectionstringinConfigurationfile
– vinodh
Aug25,2015at4:53
Addacomment
|
5Answers
5
Sortedby:
Resettodefault
Highestscore(default)
Trending(recentvotescountmore)
Datemodified(newestfirst)
Datecreated(oldestfirst)
27
YoucanspecifyconnectionstringviaConnectionStringparameter:
Update-Database-ConnectionString"datasource=server_name;initialcatalog=db_name;integratedsecurity=True;MultipleActiveResultSets=True;App=EntityFramework"-ConnectionProviderName"System.Data.SqlClient"-Verbose
AlsoyouneedtousethisparameterwiththesamevalueforAdd-Migrationcommand:
Add-MigrationVersion_Name-ConnectionString"datasource=server_name;initialcatalog=db_name;integratedsecurity=True;MultipleActiveResultSets=True;App=EntityFramework"-ConnectionProviderName"System.Data.SqlClient"-Verbose
Share
Improvethisanswer
Follow
editedAug25,2015at5:15
answeredAug25,2015at5:02
atleast3andnomorethan30atleast3andnomorethan30
8611111silverbadges1313bronzebadges
12
IfiusethiscommandimayabletoupdatethedatabaseifchangesinsinglePOCOclass.IfihavechangedmorenumberofDomaincalssField,howcaniupdate?
– vinodh
Aug25,2015at5:04
Ifiusethiscommandigotfollowingerror.Scaffoldingmigration'update1'.TheDesignerCodeforthismigrationfileincludesasnapshotofyourcurrentCodeFirstmodel.Thissnapshotisusedtocalculatethechangestoyourmodelwhenyouscaffoldthenextmigration.Ifyoumakeadditionalchangestoyourmodelthatyouwanttoincludeinthismigration,thenyoucanre-scaffolditbyrunning'Add-Migrationupdate1'again
– vinodh
Aug25,2015at5:10
6
Doesn'tworkforme.OUTPUT:Update-Database:Aparametercannotbefoundthatmatchesparametername'ConnectionString'.
– Edward
Jun10,2017at2:15
1
@Marcus-Tryusing-ConnectionStringNameastheparameter.So,ifyouhaveaconnectionstringinyourconfigfilenamedMyConnectionyourupdate-databasecommandwouldlooklikethis:update-database-ConnectionStringNameMyConnection
– MikeDevenney
Apr10,2018at0:36
1
ForNetCoreapps(EFCore5),thecommandisUpdate-Database-Connection
延伸文章資訊
- 1EF Core 工具參考(套件管理員主控台) - Microsoft Learn
Entity Framework Core Visual Studio 套件管理員主控台的參考指南. ... Script-DbContext; Script-Migration; Update...
- 2EF Core tools reference (Package Manager Console)
Reference guide for the Entity Framework Core Visual Studio Package Manager ... Script-Migration;...
- 3ASP.NET Web Deployment using Visual Studio - Microsoft Learn
Deploy the database update · Open the Publish Web wizard by right-clicking the ContosoUniversity ...
- 4Package Manager Console Commands
The Package Manager Console is available within Visual Studio by going to Tools » Nuget ... Updat...
- 5(Day 13) Model和資料庫間的一致(目前版本的Entity Framework ...
Update-Database:可以指定Migration快照檔為參數,也可不指定任何參數。 ... 現在到Visual Studio來實作Migration,我們到[工具]-->[NuGet套...