-2

I am bulding an application with MVC. Ont thing I don't understand, it's how to deploy to an hoster when building is finished and how to link database on the hoster.

Now I create the application and the database was automaticly create on first run of the application. I have create a dbcontext class, a model class (with entities) and a controller with actions.

The database was created but also a file database, I think not in sql server express.

No connection string was added in web.config, the database is in the app_data folder.

My questions are :

  • is that the database will be shipped within App_Data and the application will work without any further configuration in sql server on the hoster ?
  • is that the database will be created automatically at the first run on the hoster ?

If no, How to create a script SQL which will create the database and will be needed connection string in web.config

tks for help

David
  • 47
  • 1
  • 7
  • is your application Model-First or Coding-First? – Arif YILMAZ Apr 15 '15 at 12:06
  • 2
    Are you sure you meant to write "hoster"? Do you mean "host server", or even just "host"? I've not heard that term before. – Jason Evans Apr 15 '15 at 12:07
  • tks for reply. It's with code first. When I say hoster I say like planethoster, mavenhosting... Well I build the site and after I will choose an hoster to host the site – David Apr 15 '15 at 13:03

1 Answers1

0

is that the database will be shipped within App_Data and the application will work without any further configuration in sql server on the hoster ?

The answer is no because by default in web.config you have (LocalDb) which is a version of SQL Server that comes with Visual Studio. To make it work you have to install on server this version of SQL Server.

is that the database will be created automatically at the first run on the hoster ?

The database can be create automatically if you specify that connectionString to be over a version of SQL Server.

Note: If you use migration you can check at Publish Execute Code First Migrations enter image description here

If you can install (LocalDB) on the host server, than you can leave the connectionString as it is.

If you use other versione of SQL Server you change the connectionString to be like below, the values from Data Source, User ID and Password must be changed to match your server connection

<add name="DefaultConnection"
    connectionString="Data Source=ServerAddress;Initial Catalog=DatabaseName;Integrated Security=False;User ID=UserName; Password=UserPassword"
    providerName="System.Data.SqlClient" />
Community
  • 1
  • 1
adricadar
  • 9,971
  • 5
  • 33
  • 46
  • I am confused. With this connection string : `code .` Is the database will created auto ? – David Apr 15 '15 at 13:17
  • Another question if I give to the hoster the database file is it OK ? and what configuration will I have to do on my code or web.config ? tks – David Apr 15 '15 at 13:21
  • @David 1) The answer is no because you need to have install `(LocalDb)` see my answer for first question please. 2) It's not okay, because some one have to ***interpret*** that type of file, and that someone is called **SQL Server**, you have to install [a version of SQL Server](http://blogs.msdn.com/b/jerrynixon/archive/2012/02/26/sql-express-v-localdb-v-sql-compact-edition.aspx) – adricadar Apr 15 '15 at 13:33
  • ok but I think a hosting provider that allows .net already offers a version of sql server to their customers. so I think it 's mine to adapt me has installed version of sql server on hoster No ? and how can do that, just modify the connection string with hoster's sql server information ? tks – David Apr 15 '15 at 16:23
  • @David this really depends from one hosting service to another. First thing is to read about your hosting service after you get the information about SQL Server there ar thousand of tutorial on internet how to do what you want. – adricadar Apr 15 '15 at 17:33