I have created a Database in MVC 3 with the Code First Entity Framework and I am almost ready to deploy but i have no clue on how to Deploy the database?
I do not need the data inside of it since it was just dummy data but i do not know how to edit the webconfig file to point to the database.
You can add an entry under <connectionStrings> in the .config, as with any other DB code, but with code-first the name just has to match the name of your DbContext-derived class. Also as another approach, you can pass a name into the DbContext ctor in the
form "name=Foo" where "Foo" is the name you set in the <connectionStrings> section.
Could i maybe get a example i think thats the problem i am having i know i have to pass that dbcontext to the connection string in webconfig i just dont know how to set that up...
Here is part of my model.
public class CareersConsoleDBContext : DbContext
{
public DbSet<CareersConsole> CareersConsole { get; set; }
}
thats where the model tells it to connect it to a db
I created a MS SQL database and got the provider name and the connectionstring from godaddy to input into my webconfig.
then i did what you said to do with the controller (basically name it the same as my db context into my webconfig file)
is there anything else that could be making the problem?..Like i said i ran this already on my localhost with Code First and it ran perfectly b ut trying to get this into production its not working everytime it saysing that it has encountered a error.
But i did notice something different..the timeout was alot faster this time around rather then when i had nothing so im thinknig its created and connected but im not sure if I actually have to build the database first or if the code first still builds it
So the above connection string works with a local DB but not one hosted elsewhere? If that's the case, check for firewall issues or if their DB is even listening (Sql Server is on port 1433 by default). Not much else I can suggest or think of if it's environmental.
repeater09
Member
12 Points
20 Posts
How to connect a Code First Model Database to a GoDaddy remote Database?
Apr 29, 2012 07:50 PM|LINK
Hey Guys.
The title pretty much says it all.
I have created a Database in MVC 3 with the Code First Entity Framework and I am almost ready to deploy but i have no clue on how to Deploy the database?
I do not need the data inside of it since it was just dummy data but i do not know how to edit the webconfig file to point to the database.
any help vwould be awesome !
BrockAllen
All-Star
27574 Points
4912 Posts
MVP
Re: How to connect a Code First Model Database to a GoDaddy remote Database?
Apr 29, 2012 08:38 PM|LINK
You can add an entry under <connectionStrings> in the .config, as with any other DB code, but with code-first the name just has to match the name of your DbContext-derived class. Also as another approach, you can pass a name into the DbContext ctor in the form "name=Foo" where "Foo" is the name you set in the <connectionStrings> section.
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
repeater09
Member
12 Points
20 Posts
Re: How to connect a Code First Model Database to a GoDaddy remote Database?
Apr 29, 2012 08:50 PM|LINK
Could i maybe get a example i think thats the problem i am having i know i have to pass that dbcontext to the connection string in webconfig i just dont know how to set that up...
Here is part of my model.
public class CareersConsoleDBContext : DbContext { public DbSet<CareersConsole> CareersConsole { get; set; } }thats where the model tells it to connect it to a db
here is part of my webconfig.
<connectionStrings> <add name="CareersConsoleDB" connectionString="Data Source=|DataDirectory|CareersConsole.sdf" providerName="System.Data.SqlServerCe.4.0"/> <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/> </connectionStrings>I tried to rename it accordingly but im not even sure its reading the file?..is there a way to make the connection between the two?
BrockAllen
All-Star
27574 Points
4912 Posts
MVP
Re: How to connect a Code First Model Database to a GoDaddy remote Database?
Apr 29, 2012 08:56 PM|LINK
For this DbContext:
public class PetsDB : DbContext {...}I would need this in my .config:
<connectionStrings> <add name="PetsDB" connectionString="server=..." providerName="..." />And the other approach I said, you can do this:
public class PetsDB : DbContext { public PetsDB(string name) : base(name) { } ... } var db = new PetsDB("name=Foo");And then in the .config you could have:
<connectionStrings> <add name="Foo" connectionString="server=..." providerName="..." />DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
repeater09
Member
12 Points
20 Posts
Re: How to connect a Code First Model Database to a GoDaddy remote Database?
Apr 29, 2012 09:39 PM|LINK
I still cant get the stupid thing to work.
I created a MS SQL database and got the provider name and the connectionstring from godaddy to input into my webconfig.
then i did what you said to do with the controller (basically name it the same as my db context into my webconfig file)
is there anything else that could be making the problem?..Like i said i ran this already on my localhost with Code First and it ran perfectly b ut trying to get this into production its not working everytime it saysing that it has encountered a error.
But i did notice something different..the timeout was alot faster this time around rather then when i had nothing so im thinknig its created and connected but im not sure if I actually have to build the database first or if the code first still builds it
BrockAllen
All-Star
27574 Points
4912 Posts
MVP
Re: How to connect a Code First Model Database to a GoDaddy remote Database?
Apr 29, 2012 09:45 PM|LINK
So the above connection string works with a local DB but not one hosted elsewhere? If that's the case, check for firewall issues or if their DB is even listening (Sql Server is on port 1433 by default). Not much else I can suggest or think of if it's environmental.
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
Mike_GoDaddy
Member
86 Points
18 Posts
Re: How to connect a Code First Model Database to a GoDaddy remote Database?
May 02, 2012 12:47 AM|LINK
You can see a sample connection string that works on Go Daddy shared hosting here.
Go Daddy® Hosting Ambassador