How to publish asp.net project + Sql [First Migration] on azure - c#

I have a project and want to publish it to azure . I tried to publish it but I have no idea.
I have no problem with publishing my project, but how I can upload or publish my sql database that I created using entity framework code first migration with my project, because I have data on it also the tables , so anyone have Idea of instructions how I can publish my project with the sql database?
Update: I Published my project , after I created a db and web app on azure but I have a problem with editing my connection string , if someone can help with that ..
My deafault connection string :
<add name="SmartBookLibraryModel1" connectionString="data source=FIRAS-JC\SQLEXPRESS;initial catalog=SBL;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework" providerName="System.Data.SqlClient" />
and this connection string I got from the sql database from azure :
Server=tcp:jhm8n1ya03.database.windows.net,1433;Database=smtebooAIkF3XGJh;User ID=Firasmsw#jhm8n1ya03;Password={your_password_here};Trusted_Connection=False;Encrypt=True;Connection Timeout=30;
how the new one should be look ??
Thanks.

Basically you have to create the azure database. Add the connection string to your configuration files (web.config). Make sure the user you use in the connection string has the rights to do the changes to the database. And then deploy the project to azure.
When the application starts, the migrations will be applied to the database.
get started migrations-and-deployment-with-the-entity-framework-in-an-asp-net-mvc-application

Related

ASP.NET MVC Connection String

My website, an ASP.NET MVC app, is working perfectly inside Visual Studio with database entities and such. I want to try to upload my app to GoDaddy's Plesk Web Service.
I got a guide here:
http://www.c-sharpcorner.com/article/how-to-host-your-asp-net-mvc-website-on-godaddy-server/
which says at step 19: "Write Connection String for your server side database."
and at step 20 "Open Visual Studio again and update database from package manager, again writing same connection string in web.config of your project in Visual Studio. Open package manager console and type the following command,"
Can anyone of you please give me some advice what it means by connection string?
There is connection string in web.config file.
I am using entity framework so my connection string is as per below
<add name="yourEntityName" connectionString="metadata=res:///entity.csdl|res:///entity.ssdl|res://*/entity.msl;provider=System.Data.SqlClient;provider connection string="data source=yourServerIpAddress;****initial catalog=DataBaseName;persist security info=True;user id=YourId;password=YourPassword;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
you have to change lines in your connection string where bold line in my conn. string.

How can connect to host's db from host?

I bought a Windows hosting from GoDaddy. I have configured the configuration settings(Adding database and publishing project's files to host)
I can access the database while running the project on the local server.
But when I transfer the project to the server, the project on the server can't do it.
I wrote my connection string to web.config file, here it is:
<add name="xyz" connectionString="Data Source=IP ADDRESS;Initial Catalog=DBNAME;User ID=USERNAME;Password=PASS;Integrated Security=False" providerName="System.Data.SqlClient" />
I used MVC and Entity Framework, I also used layered structure
Thank You.
try to check more details about the connection string that should be used with your database provider. Here you can find several examples about how to create your connection string properly in SQL SERVER.
please notice that if you are working in your host machine, you have not to specify the IP ADDRES of your SQL SERVER but the SERVER NAME just like:
Data Source=(SERVER_NAME) \ DB_INSTANCE_NAME
I hope that it's gonna be useful.

Same local database from different assemblies not working

I'm trying to have one local database when using EF and code first. I have three projects - DataLayer, Web and Console App.
In Web.config in the Web project, I have following connection string:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;Database=MyDb;Integrated Security=True;MultipleActiveResultSets=true" providerName="System.Data.SqlClient" />
In the App.config in the Console App I have exactly the same connection string, but when I try to read data in the console app from the database, it doesn't find the data I've created from the web project. Why is this?
When I add the connection (Host: (LocalDb)\MSSQLLocalDB, Db: MyDb) in Server Explorer Data Connections I can see the tables with the data from the web project, but not from the console app. Both apps are using DataContext and Models from the DataLayer project.
I figured it out. Since I was running the Console App as a service logged on as system, the databases where separate. I changed the service to run as my windows account and it worked.

Publishing WPF application with a LINQ to class database

I have a WPF application holding a LINQ to class database, now I need to publish this application to work on client's machine.
I have done this but it doesn't work like if the database was not found, I think my problem is that the database is not included in the deployed files, so I need help with a clear steps to publish my application including my database.
Thanks in advance
It's not possible to interact with your .mdf database without having SQL Server engine installed on your client machine .
Try this:
Install SQL server Express on your Client machine
Attach database to the SQL Server (using .mdf or using a DB backup)
then change your connection string before deploying the application in client machine.
if you've hard coded the connection string then , you'll have to change the connection string to adjust client's machine name , or add you connection string inside app.config in order to give you the flexibly to modify it after deployment .
App.Config:
<configuration>
<connectionStrings>
<add name="Test" connectionString="Data Source=.;Initial Catalog=OmidPayamak;IntegratedSecurity=True" providerName="System.Data.SqlClient" />
</connectionStrings>
using
var connection = ConnectionFactory.GetConnection(ConfigurationManager.ConnectionStrings["Test"].ConnectionString, DataBaseProvider);
wish it help .

Switch DB From local SQL to AZURE DB with MVC5 App

I've Create MVC5 APP with Local DB like the following link(step 1 to 5)
http://www.asp.net/mvc/tutorials/mvc-5/database-first-development/creating-the-web-application
And the application is running as expected and now I need to change the DB from the
sql Lite to azure DB ,I have created the same DB in azure (same data structure)and now what I want that the application use this DB ,There is simple way to do that ?
Im using VS2013 for web.
Just change the "source" and "initial catalog" parameters of the connection string in the web.config file.
Also, SQL Azure doesn't work with integrated security so you need to remove the "integrated security" parameter from the connection string and add the parameters "User ID" and "Password" with the credential of a user that you created in SQL Azure.
Open Visual Studio In Solution Explorer
find the file web.config
Look for the section connectionStrings
You should find something similar to:
<add name="testEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\test.mdf;integrated security=True;connect timeout=30;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
You need to:
Replace (LocalDB)\v11.0 with the name of your server
Remove "attachdbfilename=|DataDirectory|\test.mdf;integrated security=True;"
Add "Initial catalog=[name of your database in SQL Azure];user id=[name of your user id on SQL Azure];password=[your password]

Categories

Resources