I'm currently setting up two websites using one web role on Windows Azure. When I deploy the sites to Azure they deploy successfully, but I get a warning:
Warning 1 The connection string 'DefaultConnection' is using a local database
'(LocalDb)\v11.0' in project 'GTCompanySite'. This connection string will not work when
you run this application in Windows Azure. To access a different database, you should
update the connection string in the web.config file.
I've attempted several solutions: I published the second website and referenced the physical path to the published folder. No luck. Both websites reference the default LocalDB, but also seem to correctly hook up to the Azure Storage service. I haven't messed with those settings at all.
Any pro-tips for solving this issue?
Regards,
Jesse
In a local environment it iss possible to connect your application to a Local SQL Server Express Instance.
However when you deploy to Azure you'll need to connect your app to an actual running SQL Server Instance. A SQL Azure Instance is probably your simplest option as you can easily spin one up through the Azure Management Portal. (Though you could also host a regular SQL Server Install on a VM)
Once you've created your SQL Azure Instance, you'll be provided with all the Connection and Auth credentials you need. You'll need to change the DefaultConnection connection string in your Application Configuration or CSCFG file depending on where your storing it to point at the new SQL Azure Instance, instead of a SQL Express before you deploy your app.
<configuration>
<connectionStrings>
<add name="DefaultConnection"
connectionString="Server=tcp:[serverName].database.windows.net;
Database=myDataBase;
User ID=[LoginForDb]#[serverName];
Password=myPassword;
Trusted_Connection=False;
Encrypt=True;"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
Related
This question already has an answer here:
appharbor connection string
(1 answer)
Closed 7 years ago.
I am using asp.net identity with EF data first approach. Everything is working fine on localhost. I have hosted my website on appharbor. All of my controllers actions and webapi is working fine except AccountController. When a user tries to signup it gives the Internal server error. The details of error is:
Note: My database queries are working fine. It means there is no issue in connection string.
And to enable remote connections SQL Server Network Configuration does not has the option Protocols for SQLEXPRESS
How can I tackle this issue?
Update:
My connection strings in web.config are:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-Inspinia_MVC5_SeedProject-20141215093835.mdf;Initial Catalog=aspnet-Inspinia_MVC5_SeedProject-20141215093835;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="Entities" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string="Server=b1ad1f3e-1ab5-4169-93f8-a5ae006f3e4e.sqlserver.sequelizer.com;Database=8a5ae006f3e4e;User ID=namucclqps;Password=54nWBkCfURyMzYfhbu8NUQb6PEZUsWcoN;"" providerName="System.Data.EntityClient" />
</connectionStrings>
Update 2:
I installed SQL Server Management Studio. Then I hosted my website on appharbor and installed add-on SQL Server. Then using following info I connected to Server.
Then added tables in SQL Server Management Studio and changed connection string in web.config and published website.
LocalDB is only a thing inside Visual Studio. There's no way to even get it on a production server. You need to install some version of SQL Server and then create your database and tables there.
After that, leave the original connection string inside Web.config alone, and instead, add a transform in Web.Release.config that changes the connection string to the one for your production SQL Server instance of your database. Finally, when publishing your site, select the "Release" configuration. The Web.config will then be transformed during publishing and will reference the production database once the site is deployed.
I have two .NET applications, one running on 2.0 and the other running on 4.5.
The .NET 2.0 application is the main application where the user inputs data and this runs perfectly. The .NET 4.5 application is a Telerik Reporting site that runs a report based on data entered in the 2.0 application and is receiving the error below
system error 32 (the process cannot access the file because it is being used by another person)
Both applications are using this the connection strings below.
<add name="sqlserver"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=c:\FolderName\Database.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient"/>
I set up SQL Server Express to use windows authentication but I can't seem to get it to work. Any help would be greatly appreciated.
You can't. SQL Server process holds a lock on the file while it's up and running.
But alternatively, you can setup a database server and point both apps to the same database.
Or have two instances with replication.
Database files are good for development, but not to be used in production environments.
In development, i.e., when using Visual Studio and its built-in IIS Express instance, I have set up my web app to use LocalDB, with the data MDF file located in a directory on my computer but not inside the project directory, e.g., "C:\MyAppData\MyAppData.mdf", not "C:[...]\MyAppProject\App_Data\MyAppData.mdf."
This is working just fine when using Visual Studio/IIS Express, and the connection string being used looks something like this:
<add name="MyAppEntities" connectionString="metadata=res://*/MyAppModel.MyAppModel.csdl|res://*/MyAppModel.MyAppModel.ssdl|res://*/MyAppModel.MyAppModel.msl;provider=System.Data.SqlClient;provider connection string="data source=(localdb)\v11.0;attachdbfilename=C:\MyAppData\MyAppData.mdf;integrated security=True;connect timeout=30;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
My question is, after I deploy the app to a development web server, is it possible that the app can connect to that same MDF file hosted on my computer? If so, how? If not, why not? Note that I am not publishing the MDF file to the development web server: I am trying to access the MDF file on my computer from the app that is running on a web server.
My assumption would be that the web app would use the connection string to look for that MDF file on whoever's computer is running the app, but apparently it is not this simple and may not even be possible?
It won't work. You need to setup, perhaps, a SQL Server Express instance in a local PC, and inside create a database similar to your MDF (or just export it outright). You can connect to this SQL Express instance changing the connectionsString to a (example) "SERVERNAME" and referencing the database. A great example is at http://www.connectionstrings.com/. SQL Server Express is free, and also fairly more robust than anything internal in VS.
I have an N-Tier MVC4 project connected to an SQL server database.
The MVC4 project was created using the MVC internet application template in VS.
I'm trying to deploy this project to windows azure.
The website was added to azure with no problems the database was added with no problem as well.
When i browse to my website it's there but when i try to do actions related to the DB such as register/login/view a certain list i get the error:
"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections."
my development connection string is:
<add name="CarRentalDataBaseEntities" connectionString="metadata=res://*/CarRentalDataBase.csdl|res://*/CarRentalDataBase.ssdl|res://*/CarRentalDataBase.msl;provider=System.Data.SqlClient;provider connection string="data source=CONSTANTINE-PC\SQLEXPRESS;initial catalog=CarRentalDataBase;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
my production connection string is:
<add name="CarRentalDataBaseEntities" connectionString="metadata=res://*/CarRentalDataBase.csdl|res://*/CarRentalDataBase.ssdl|res://*/CarRentalDataBase.msl;provider=System.Data.SqlClient;provider connection string="Server=tcp:ptuwjgqh7p.database.windows.net,1433;Database=CarRentalDataBase;User ID=XXXX;Password=XXXX;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
when i run the project in VS it works fine with no problems, which means that remote connections allowed to the database.
Seems that there something wrong with the connection between the website and the database in azure but i dont know what.
please advise what can i check in order to find the problem.
Thank you.
EDIT:
I just created draft MVC website that has a connection to a database and it worked - There is a connection to the DB in azure.
The difference was that this website wasnt N-Tier designed meaning it didnt have a business logic project.
In my original website (the one that i still didnt manage to connect to a DB) there is a business logic project and the database edmx file is on that project.
The publish to azure that i did was to the MVC website project that has a reference to the business logic(which has the edmx DB file).
Any suggestions on the latest findings?
Thank you.
Eventually I found that in the publish menu, in Settings under databases, from some reason, the connection string did not match the connection string in AppConfig and Azure management portal all though I performed a Clean-Rebuild on the entire solution before publishing.. Anyway mystery solved after almost a year!
On the firewall section of the portal for that server have you turned on access to Azure Services?
Fairly simple question about connection strings using an ASP.Net MVC web application with a SQL server Database.
I created a Web application which uses a database, using the default templates for an MVC 5 application using Visual studio 2014.
I am moving my application over to a IIS and sql server express database (2014) and I see that the database my application uses is a localDB (has a .mdf extension) what I need to know is how to attach it to my SQL Server Express database. (The development Machine and the Server are separate machines)
I have attached it to the server and have a login "IIS APPPOOL\DefaultAppPool" for my IIS to be able to use the server. Here I have granted the login read and write permission to the database "aspnet-owinTest-20140519094353" and my connection string in IIS is
Server=KEVIN-PC\SQLEXPRESS;Database=aspnet-owinTest-20140519094353;Integrated Security=true
The default connection string when building my application is:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-owinTest-20140519094353.mdf;Initial Catalog=aspnet-owinTest-20140519094353;Integrated Security=True" providerName="System.Data.SqlClient" />
If anyone can please give me a hand with this. My application simply throws an error
Error.
An error occurred while processing your request.
This is the default MVC error.
Also are there any ways where I can see what happened? As in a log of sorts, I checked in the IIS log and there did not seem to be any information that would help me. Would it be better for me to just have a login that used a Username/Password rather than using Windows Authentication?
I believe I found what I was looking for:
How to deploy ASP.NET MVC 4 application using localDB to local IIS on Windows 7?
This did the trick, though probably not a good idea for production server.
I guess one would have to do some type of restore on the SQL server from the .mdf.
All one has to do is publish their files, drop them in the wwwroot folder (along with the app_data folder containing your database and logs) and set the pool to local and you should be set.
If you are quite new to Visual Studio and facing this error, the very first thing I would suggest to check is INCLUDE all the files from the project. If there are some dependent folders or files which are left as excluded, this very error message is thrown back to browser.
To do this, first click on the icon of "Show All Files" and check for any of the expected files which you created/added but didn't include in the project. If you find one, then right click and include it.
If there is any quicker way to identify/avoid any such excluded files/folders issues, then please share below in comments.