none
Code First Dtabase Initialization Question RRS feed

  • Question

  • So I am working on changing what was once a database first model into a code first model.  The hang-up comes in when I try to intitialize the database.  I do not want to grant create/drop priveledges to all users though it seems that to even debug the code first process wants to hit the master even when told what initial catalog to access.  I am not sure what can be done but is there a workaround so that when the database intializes it knows its hitting an existing DB as well as does not need admin rights?  I hope that was clear:

    -Code first with an existing database

    -Code first wants to access the master to assure the database exists

    -To access the master there must be admin priveledges

    -I want to only allow create/drop etc priveledges to certain users etc..

     For clarification I might just be missing something...I know the line:

    DbDatabase.SetInitializer<Insert context name here>(null); should work to disallow create/drop stuff and simply access the db but then I get a provider manifest token so I am not really sure where to go with that...I get:

    The provider did not return a ProviderManifestToken string. exception..

     


    Wednesday, August 31, 2011 3:47 PM

Answers

  • I discovered my error.  Because the code first app was contained within a Silverlight web application I had to place the connection string from the app.config within the web config of the Silverlight application.

    I also then had to as Alan stated map all the entities to their exact name within the database because some naming conventions were different in SQL than in C#.

    • Marked as answer by DevGuyMatt Sunday, September 4, 2011 9:04 PM
    Sunday, September 4, 2011 9:04 PM

All replies

  • Setting initializer to null should not result in the exception you are seeing. Does the "The provider did not return a ProviderManifestToken string" exception contains an inner exception? What does it say?

    Pawel

    Friday, September 2, 2011 8:56 PM
  • Hi Mr_Kunstman,

    Code First can work with an existing database, you just need to map the entities and give the right connection string.

    I think you have read the blog here: DbContext, right?

    If you have not done any other configuration in your application, then calling the string constructor on DbContext with the database name you want to use will cause DbContext to run in Code First mode with a database connection created by convention to the database of that name.

    you can use the form “name=<connection string name>” for the string passed to the DbContext constructor to map the existed database.(Connections).

    I think this link is helpful, you can refer here: Code First Walk through

    >>The provider did not return a ProviderManifestToken string. exception

    Would you please feel free to clarify it.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Sunday, September 4, 2011 10:11 AM
    Moderator
  • I discovered my error.  Because the code first app was contained within a Silverlight web application I had to place the connection string from the app.config within the web config of the Silverlight application.

    I also then had to as Alan stated map all the entities to their exact name within the database because some naming conventions were different in SQL than in C#.

    • Marked as answer by DevGuyMatt Sunday, September 4, 2011 9:04 PM
    Sunday, September 4, 2011 9:04 PM