Currently I have my project connected to the database placed on Windows Azure, but I will be soon publishing my website for other people. When I'm making changes to my site, I often make changes to the database too. So during my work on my site, public webpage will not work.
How can I create local database which will be used locally, while testing and how can I automatically switch to this public db when my project is in Internet?
I use Asp.Net MVC5 with Entity Framework.
This is what Configurations are for in Visual Studio. You put your development connection string in your Web.config for development, and then in Web.Release.config, for example, you add a transform to change that connection string to the production version. Then, when you publish the site, you select the appropriate configuration, "Release" in this example, and the published Web.config will contain the production connection string. More information on configurations and using Web.config transforms can be found at MSDN.
Related
I have an app made with ASP.NET Core and I published/deployed it to IIS. It has a database with multiple tables, and multiple rows of data. I was tasked with recreating the web app again and improving it. I used ASP.NET Core again, this time the database and tables are all different. I am using the same url as the old one, just a different app with different database.
My question is, can I just add the connection string in the appsettings.json file to the new app with just a different database name and transfer the publish profile over to the new app? Can I do this and it will add the new web app to the url and simply override the other web app currently running on it? If so do I need to create the database on the server before hand, then reference it in the connection string? Or when I publish the new web app, the new database will be created?
I can add more details if necessary. I just want to know if connecting the new app will be as easy as adding the same connection string. Here is appsettings.json currently running
{
"ConnectionStrings": {
"DefaultConnection": "Server=Server-Name;Database=DatabaseName;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"https_port"; 443,
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
}
}
To be more specific. I just want to add replace the current web app with the new one. The database, code is different in the new app. I just want to use the same url which is hosted on IIS server, but with different code. Basically I don't want to buy a new domain name from somewhere. I want to push new project onto server and host it.
Can I just change Database=DatabaseName to Database=NewDatabaseName inside the connection string?
From the comments, it seems like you are trying to host two applications in IIS under the same domain.
When doing it manually, you simply "Add Application" in your site.
If you are publishing it from Visual Studio, you can do a Web Deploy or publish to a folder.
Web Deploy: https://learn.microsoft.com/en-us/visualstudio/deployment/tutorial-import-publish-settings-iis?view=vs-2019
Publish Folder:
Create an application manually in IIS.
Share the app folder with you.
Publish from Visual Studio to the folder.
Having said that... I don't recommend publish to your production directly from your machine. I recommend using a CD pipeline from your repo. If you don't have one yet, I recommend using Azure DevOps.
I did it and all I had to do was create the new database on the IIS server in SSMS, create a folder to publish the code to on the server, and also direct the url to point to the folder in IIS.
On my app, in appsettings.json, just copy the same connectionstring over from the old project to the new project, just update the database name.
This did what I expected, just replaced the url/website, with the code from my new app.
I created a simple ASP.Net Core application with user authentication (so all the Entity Framework has been preloaded into the web app template). It is connecting to my database with the connectionString that is located in my appsettings.json file, with "data source = {computerName}\\{serverName}" setup.
The database instance and Visual Studio are located on the same machine. This works fine in returning data to the web api while within development and debugging mode. When I publish it and try to go to the site from a domain name it does allow me to view the webpages that are not needing database connection but the rest that need data from the database returns pages like this:
Error.
An error occurred while processing your request.
Development Mode
Swapping to Development environment will display more detailed information about the error that occurred.
Development environment should not be enabled in deployed
applications, as it can result in sensitive information from
exceptions being displayed to end users. For local debugging,
development environment can be enabled by setting the
ASPNETCORE_ENVIRONMENT environment variable to Development, and
restarting the application.
I have tried to change the Environment Variables for ASPNETCORE_ENVIRONMENT from Development to Production to no success.
I have tried adding appsettings.Production.json to publishOptions in my project.json file, even though there is no file appsettings.Production.json, and this did not help. dotnet publish
Adding the evironment variable in the web.config file did not work Deployment
I need help getting the published web api to connect to my SQL Server database from outside the development Visual Studio setup.
The last thing I can think of is that maybe I am incorrect in how I understand the connection string. If the web api uses the connection string to connect to the database from the server-side then it should work just fine like it does when in development calling to http://localhost:port# since it's all on the same machine. But, if the database string needs to be based on a client-side call then it would have to be with domain names and IP addresses.
Can someone tell me which one it is?
The only thing else that comes to mind is that there is something I am not doing, and need to do, inside of IIS Manager. I see connect string there as well but unsure what that is for our does since the connection string is inside the application. Also maybe I am suppose to give the app some kind of authorization to communicate with the database server even though they are on the same machine???
After much research, finally googling "how to deploy a web api in iis" I was able to learn from Host ASP.NET Web API in IIS using Visual Studio Publish that I needed to add the security entity BUILTIN\IIS_IUSRS. Then placing a mapping to my database tables and giving db_datareader (and possibly db_datawriter) for the database to the IUSER to allow access from my self hosted IIS web api. This from the above mentioned link with the part stating
Accessing Database under IIS APPPOOL\ASP.NET v4.0
As we are using ASP.NET v4.0 App Pool make sure IIS APPPOOL\ASP.NET v4.0 is added to your Database Server -> Security -> Logins.
I have an ASP.NET MVC5 web application that was originally created using VS2013 and uses Entity Framework 6 Code First, with data migrations. It has been working fine (in production) for almost a year and has been re-deployed numerous times, from Visual Studio, using Web Deploy.
Today, I opened the solution in VS2015 and redeployed a known working version of the codebase to production without any problems. However, after deployment, the production website suffered from the problems described in this article, which I solved by applying author's the recommended fixes.
After applying these fixes, I now have a new problem: an exception that suggests that the application is trying to access the database using the wrong connection string:
Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path. Please make sure the user has a local user profile on the computer. The connection will be closed.
Within the details of the exception page, the cause of the problem is clarified:
The connection string specifies a local Sql Server Express instance using a database location within the application's App_Data directory.
I'm puzzled by this because the application has a dedicated SQL Server instance that is accessed using a regular connection string. I've checked the Web.config generated by Web Deploy and it seems to be intact. It contains a named connection string that correctly references the production SQL Server instance, and the code (which hasn't changed) correctly instantiates an Entity Framework ApplicationContext using the named connection string.
Does anyone have any idea why this application now expects to create its own SQL Server instance or what I can do to debug this problem?
Many thanks for your suggestions,
Tim
A few things you can try before making the web deploy:
Check if the project that contains the connection string declaration (web.config) is setted as the 'startup project'.
Rebuild the solution in release mode.
In the Publish Web wizard, in Settings, expand File Publishing Options and check 'Remove additional files at destination' and 'Exclude files from App_Data folder'
I just started working with Kentico and after Kentico Installation there is no setup files for my sql server database but I get the files are locally stored in the database(on localdb). So now I want to know that how can I connect with the existing database(sql server). As I try to change the web config but there are issue when we run the service from Kentico Service Manager.
Also I am having an another issue that how can this be possible with kentico that if the admin made certain changes in the text through interface and those changes should be reflected in database as well.So that next time when anybody tries to access the website it will reflect to him. Please let me know about it. Thanks in advance.
Please, refer:
Connecting your project to the database
Daabase Setup
Managed projects are connected to the database and contain Kentico EMS data by default.
If you're using an unmanaged project, you must connect the project to the database manually. You have two options to connect your project to the database:
entering the database credentials into the database setup wizard
adding a connection string to your application's web.config
Connection string template
<add name="CMSConnectionString" connectionString="Persist Security
Info=False;database=DATABASE_NAME;server=SERVER_NAME;user
id=USER_NAME;password=PASSWORD;Current Language=English;Connection Timeout=240;"/>
I am new to umbraco and I tried to create an application using it . I created an empty mvc application in visual studio 2013 and add UmbracoCms nuget package( Version 7.1.4). When I ran the app it asked for installation and is successfully installed in a local SQL CE database.
I added the required Controller ( inheriting SurfaceController) and the model required in my partial view . The project compiled and the page worked fine.
Now I need to deploy this site to Microsoft azurewebsites. When I publish the site from visual studio publish option(I specify the website name, sql azure db name and credentials ) to azure the whole publish process gets successfully done. When I browse the site it goes the page that reads "Looks like there's still work to do" and when I click the "Set up your new website" button it goes to the login page "http://XXXXX.azurewebsites.net/umbraco#/login/false". I don't have the credentials since this is a new deployment and I also tried the local one but it did not work either. I believe that the sql azure db is not setup for this. I was of the opinion that when I run the site it willl take me to the installation page . But it did not.
Any help on this would be really appreciated.
Thanks.
Since you installed umbraco locally with SQL CE the web.config gets updated with the current version (its an appSetting) and a connection string. When you then deploy that to Azure it will look like the site is already setup.
Now, I don't know if you included the SQL CE database in your deployment package because with that the site would work (with the credentials you choose locally). But ideally you'd want to set it up with a SQL azure database. To do this you can "reset" the umbracoDbDsn connection string in web.config and remove the version in appSettings. Doing that will make Umbraco start the installation when deployed to azure.
In the umbraco installer you simply choose Customize to get the dialog that always you to enter a connection string for SQL azure.