Issue connecting to SQL Express - azure

I have two visual studio 2010 projects that I am running locally. One is a cloud project and connects to azure table (development) storage in addition to a local SQL Express, the other is not a cloud project. Both projects attempt to connect to a local SQL Express database via similar code generated through an xsd as well as directly in an aspx via a databound grid. The non-cloud project connects fine, but the cloud project fails with the common error:
"An attempt to attach an auto-named database for file C:\Users...mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share."
Both projects use the same connection string in a Web.config file:
<add name="WorkoutLogConnectionString1"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\...mdf;
Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
In VS2010 server explorer from the cloud project I can connect to the express database just fine, but when the project runs, it fails to connect. The cloud project also connects to a SQL Azure remote cloud database via another connection string in Web.config and that connection works fine.
I saw the MS support article: http://support.microsoft.com/kb/2002980 and thought that maybe the projects were originally created with different versions of VS and that maybe causing my issues, so I made the suggested IIS changes to the ASP.net 4.0 application pools, but to no avail.
Since the SQL Express connection string works in one project and not in the other I am stumped. Are there some other configuration elements or something related to the failing project being a cloud project that I should be looking at?

Are you tyring to run both the project simultaneously (at the same time - multiple startup projects). If so, it is indeed common issue with SQL Express. Often happens also when you have opened the database in your VS Server Explorer. If you have multiple applications accessing the same database, I suggest that you manually attach the database in your SQL Server Express. You can do by:
open SSMS (Sql Server Management Studio), connecting to your local SQL Express instance.
Navigate to Databases branch
Right click -> Attach Database
Browse to your mdf file
Done!
Now change your connection to the one suggested by Aaron. Generally I advice to now use the AttachDbFilename and UserInstance, but instead attach the database directly and use it as with a regular stand-alone instance of SQL Server. Saves lots of headaches.

Have you attached your database to an actual SQL Server Express instance? If so, remove all that AttachDbFilename and User Instance nonsense. To keep things simple and consistent you could probably use SQL Authenication locally. So you should just have something like:
<add name="WorkoutLogConnectionString1"
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=DatabaseName;
User ID=SQLAuthUsername;Password=password" providerName="System.Data.SqlClient" />

Related

How to open Azure database .bacpac locally for local Umbraco website?

I exported and downloaded my database from Azure as a .bacpac file.
I want to install Umbraco locally and use this database locally.
How do I do it?
Every time when I open the Microsoft SQL Server Management Studio it tries to connect to the database on Azure:
Then when I put the password it will connect to the database on Azure:
But I want to work on the local .bacpac file.
My questions are:
How do I connect on the Microsoft SQL Server Management Studio to the local .bacpac file ?
How do I connect in the Web.config to the local database ? What should I put in the connectionString?
<connectionStrings>
<remove name="umbracoDbDSN" />
<add name="umbracoDbDSN" connectionString="Server=tcp:xxxxx.database.windows.net,1433;Data Source=xxxxx.database.windows.net;Initial Catalog=xxxx;Persist Security Info=False;User ID=xxxx;Password=xxxx;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=3600;" providerName="System.Data.SqlClient" />
</connectionStrings>
So basically I want to open and work on the local .bacpac and not on the one on the server, and only after I finish the work to deploy it back.
How do I do it?
Thanks
Here are the steps that you should follow;
Connect to your local db.
Select Import Data-tier Application.
Select your .bacpac file.
Give a name to your new database and hit finish.
Create a new login or choose one of the existing ones and set the user mappings as follows so that you can connect to your new Umbraco db using this user's credentials.
And here is how you can connect to your local db from your local Umbraco website:
<add name="umbracoDbDSN" connectionString="server=localhost;database=YourNewUmbracoDbName;user id=youruser;password=yourpassword" providerName="System.Data.SqlClient" />
The .bacpac file is essentially a backup of another database, so you can't "open" or "connect" to it directly. You need to restore it on your local database server. Which, by the way, you might not have installed as it isn't part of Management Studio. When you open Management Studio you can just click Cancel on the Connect dialog that has your Azure server in it, and then maybe follow one of the many guides available via Google ;-) Like this one, maybe: https://www.netreo.com/microsoft-azure/how-to-restore-sql-azure-bacpac-to-local-sql-server/
Thanks a lot for your help!
I was able to install Umbraco locally.
Just one step I had to do before importing the database locally, is setup a local sql server, which I found a good explanation here:
Create Local SQL Server database
Create Local SQL Server database

web app with local db .mdf file how to publish to Azure

I have a web app published on Azure.(created locally via visual studio)
I ve also migrated my main Database(Azure Sql database) and connected with the web app and of cource already created an sql server instance.
My problem is with my local db file .mdf file in my App_Data folder.
When i published my app returned error below:
provider: SQL Network Interfaces, error: 52 - Unable to locate a LocalDB installation. Verify that SQL Server Express is properly installed and that the LocalDB feature is enabled.
How to attach .mdf file ? and associated it with my sql server instance?
Thanks
I think you can't use SQL Server Express (pretty sure there is no Express installed). Why do you want to use SQL Server Express?
Anyway, you can migrate it to Azure into SQL Server Compact - http://www.asp.net/mvc/overview/older-versions/deployment-to-a-hosting-provider/deployment-to-a-hosting-provider-deploying-sql-server-compact-databases-2-of-12
But that way is not very efficient if you plan to implement any type of replication - any instance will have own db - and some other drawbacks.
I believe that the best way here is to use SQL Azure and migrate your data into it if there is no need in something like SQL Server Compact/Express.

How can I deploy my database from SQL Server 2008 Express to Azure SQL Database

I am using Visual Studio Community 2013, SQL Server 2008 R2 Express Edition for an MVC web application using entity framework code first migrations for my database.
I am trying to get my local application hosted on the Microsoft Azure platform.
I have registered for a trial account which expires in 30 days, and deployed my MVC5 app out which has been successful.
However, this app requires a database which I am struggling to deploy.
What is the easiest way to get my database deployed out to Azure as I do not seem to have the :
"Tasks" -> "Deploy Database to Microsoft Azure SQL Database" option available to me in SSMS.
I have extracted a Data-tier Application of my local database and have it stored on my C drive, however if I connect to my Azure Account in a second window, and right click the server then select Deploy Data-tier Application, it fails on "Creating schema object in database" with the following error:
TITLE: Microsoft SQL Server Management Studio
An exception occurred while executing a Transact-SQL statement or
batch. (Microsoft.SqlServer.ConnectionInfo)
------------------------------ ADDITIONAL INFORMATION:
Users cannot be mapped to certificates, asymmetric keys, or Windows
logins in this version of SQL Server. (Microsoft SQL Server, Error:
40528)
I'm assuming its tried to create my local account plus the IIS APPPOOL account I had to set up to host the website on my local network, however I do not see a way of removing them from the .dacpac export.
When I refresh the Databases node, there is still no database, I'm fairly lost now as to how I might get my db deployed to this server?
If you can extract a compatible Data-tier application and then Deploy it to your target server using your current version of Management studio, then this approach should work, see this link for more reading on ensuring your database is compatible.
Failing this, as was in my case. I downloaded Management Studio 2015, which gave me the option to deploy database to Azure by simply right clicking the required database.
Again, this threw up the error regarding my database level IISAPPOOL user, but not my server account user. As a way around this, I took a backup/restore of the database and removed this user then deployed the copy database obviously minus the problem account.
Now all that was left to do was add a transform to my Release web.config with the Azure connection string as provided on the Azure dashboard, and re-deploy the website.
Problem solved.

Already an open DataReader associated with this Command which must be closed first?

I am experimenting with EF7 beta 4 in combination with Azure web apps. Strangely:
1. A local web server / local db setup works;
2. A local web server / azure db setup works;
3. But: the Azure web server with azure db setup does not work. This results in the following infamous exception:
InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first.
The connectionstring I use is as follows (currently the same on local web server and Azure web server):
Server=...database.windows.net,1433;Database=...;User ID=...;Password=...;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;MultipleActiveResultSets=true
What do I have to do to get it running?
I had exactly the same problem when using Azure SQL Database.
My web.config files had the same flag in relevant connection strings. Everything worked fine locally but it didn't work when I published my solution into azure as web app.
MultipleActiveResultSets=true
The reason is that web.config files might be overwritten in your publishing profile. You need to add that setting explicitly like below:

Visual Studio 2012 - Windows Azure : connection string not working (no database interaction)

I'm trying to put my Visual Studio 2012 MVC 4 project online using the Cloud Technology provided by Windows Azure.
Although i can get to my website (it uploads well and is accessible), I can't manage to make the data connection work.
For exemple, when I try to register a new user to my live application, it returns me a simple mistake : "A mistake happened while handling your request" (that's a translation from french, though... --')
I've followed a bunch of tutorial all around the web, but none seems to make things work.
Here's the connection string I actually use :
<add name="yoombysql"
providerName="System.Data.SqlClient"
connectionString="Data Source=tcp:rmy11na948.database.windows.net,1433;Initial Catalog=yoombysql;Integrated Security=False;User Id=yoomby;Password=PASSWORD;Encrypt=True;TrustServerCertificate=False;MultipleActiveResultSets=True" />
It's not the only thing I've tried, but i'm running out of ideas... So if anyone had a hint or a clue on this...
Thanks in advance !
Make sure that in your control panel for the DB rmy11na948 on the right side under "Manage allowed ip addresses" you have checked WINDOWS AZURE SERVICES = "YES" and if you are accessing Azure SQL outside of Azure, you need to add your specific IP address for testing.
UPDATE: You should add the full userId as well User Id=yoomby#rmy11na948;
Again, from the portal on the right side click "Show connection strings", copy the ADO.NET connection string and replace the {your_password_here}. If that fails, then walk through the steps at Windows Azure SQL Database Firewall.
UPDATE-2: For Entity Framework connections, read How to: Connect to Windows Azure SQL Database Using the ADO.NET Entity Framework and read Entity Framework and SQL Azure

Resources