Azure cannot connect to SQL Server - c#

I am an Azure newcomer.
I went through
Get Started with Azure Cloud Services tutorial and can run the Contoso Ad app locally.
When I push it to my dev/test Azure account, the app cannot see the database.
You can see it live here: My Dev/Test Azure instance running Contoso Ad App
I can run SSMS locally and connect to my database:
(this works fine)
I did have to add my home IP Address to the Firewall rules:
Questions:
Is there any way I can see more about what Azure doesn't like when trying to connect to the database?
I followed the tutorial step-by-step, and I'm sure my connection Strings are correct, especially since I can connect from SSMS at home. Any firewall changes that need to be made so an Azure Web App can see an Azure SQL Server database?
Thank you very much in advance!

This turned out to be me not fully understanding how
Web.Config
Web.Debug.Config
Web.Release.Config
interact.
I learned that Web.Release.Config is only modifying upon a Web/Azure Publish, so I did not see the changes reflected in the local <project>\bin\Release folder.
I also learned that by changing the Connection String name in Web.Release.Config, this caused it to not match and transform/overwrite the value in Web.Config.

Related

Publish web-site vs Azure Cloud service publish

There are 2 ways for publish website to Azure - via simple Publish feature vs Deploy as Cloud service. I have also one worker role in solution, so, I selected Cloud Service instead of simple Publish website feature.
But I'm very disappointed with Cloud service. First at all, deploy as cloud service takes in 10 times more time, than simple Publish website. Second problem - I have to each time, when I want to deploy, change connection strings in web.config to SQL Azure (instead of my local SQL Server). Website Publish has ability to set necessary SQL connection strings for deploy. Maybe I do something wrong and deploy can doing in 10 sec and exist ability to set different connection strings (like Website publish)?
I think about put to Cloud only worker role and website deploy as website, without Cloud service...
First, I would highly recommend that you go through this question comparing Azure Websites and Cloud Service: What is the difference between an Azure Web Site and an Azure Web Role
Now coming on to your questions:
First at all, deploy as cloud service takes in 10 times more time,
than simple Publish website.
It is bound to happen because when you deploy a cloud service (say through Visual Studio), following things happen that will cause the delay:
As a part of build process for cloud services, Visual Studio creates a package file and uploads it into blob storage. This package is then used to create a cloud service.
Azure Fabric Controller which is responsible for managing life cycle of a cloud service creates a brand new Virtual Machine for you, installs necessary software (IIS for example) and then deploys your code from the package file.
Both of these things don't happen in websites.
Second problem - I have to each time, when I want to deploy, change
connection strings in web.config to SQL Azure (instead of my local SQL
Server). Website Publish has ability to set necessary SQL connection
strings for deploy. Maybe I do something wrong and deploy can doing in
10 sec and exist ability to set different connection strings (like
Website publish)?
You're not doing anything wrong per se. Your web.config file gets bundled into the package file so after any change you make to your web.config file, you would need to recreate the package and update the deployment (which will include uploading to blob storage).
One possible solution for your problem would be to use config transformation and have your web.config.release file contain the connection string for your production database. When you build your project in release mode, you will have correct connection string in your web.config file.
I think about put to Cloud only worker role and website deploy as
website, without Cloud service...
This is certainly a viable option. Another alternative would be look into WebJobs. Like Worker Roles, they are meant for handling background processing workloads but have the same convenience of a website when it comes to deployment. You may also find this blog post useful as well: http://www.hanselman.com/blog/IntroducingWindowsAzureWebJobs.aspx.

Azure - 'Microsoft.ACE.OleDb.12.0' provider is not registered on the local machine

I am working with MS Excel files in my web application is hosted on Azure
I never run into following error when I am trying to access the excel file on my development fabric, but once I deploy to Azure, I get this error message.
The 'Microsoft.ACE.OleDb.12.0' provider is not registered on the local machine.
I do not want to change my code and cannot use any 3rd party tool. My questions are:
Is there a way around this issue?
Can I create a VM on Azure, install the OLEDB Driver and upload my site there?
No such support is there. I guess the development fabric is flawed in this area of azure
You can do anything with an Azure VM that you can with a local machine :)
Just create one through the portal, login to it and go here:
http://www.microsoft.com/en-au/download/details.aspx?id=13255
Based on this post you may also need to download SQLEXPR_x86_ENU.exe from here and tick Allow In Process calls in the provider.

Unable to connect to any of the specified MySQL hosts with c# and mono

I'm having trouble connecting to the MySql database. I googled around, but could not find a solution that worked for me. I have a console app written in c# that works on my localhost. Connects to the database and just works. When I then use this app and run it with Mono, I cannot connect to the database. Thinking it was a permissions issue based on some of my googling, I checked the grants for the user I'm trying to connect with, and it says:
GRANT ALL PRIVILEGES ON *.* TO 'root'#'localhost' IDENTIFIED BY PASSWORD...
(This is me ssh'ing into the machine and checking the grants of its localhost).
So that part is set up correctly. My coworker has another console app that connects to the database, and I just copied and pasted what they did to connect, but for some reason, I'm not able to connect. Other there are other troubleshooting things I should look out for? Thanks.

Can't connect to SQL Server database

I'm currently developing a web application using asp.net c#. I got a server where I today was
going to publish my website and its database. Its a server that runs Windows Server 2008 R2.
But I have one issue:
My website doesn't seem to get access to the database. If I run the website from another computer on my local network I can access the server's database, BUT I can't when I run the website from the same server where the database is. This is really weird. I hope someone can help.
I just get an error that says, it can't access the database.
The most weird of all is that I'm using the same connection string on both computers, but it still doesn't work. Are there maybe some sort of settings in Windows Server 2008?
Here is my connection string:
<add name="ConnectionString"
connectionString="Data Source=AXELS;Initial Catalog=Sailor;Persist Security Info=True;User ID=sa;Password=saab123"
providerName="System.Data.SqlClient" />
Since the connection works on one machine and not on another, I'd guess you have an issue with a firewall or similar - but it will be hard to tell until we see the actual error message. Until then, there are a few things you might want to do:
If it appears as if the connection has to time out before you get the error, it indicates a connectivity problem. Do you have a firewall between the two servers? Does the database server have a firewall that explicitly lets your machine (or internal) machines get through, but hasn't been setup to let the webserver get through? You have to make sure that port 1433 is open on the server.
Are there other sites on the webserver that can connect to the database?
If you have console access to the server, try to set up an ODBC from the server to the database - usually in Control Panel -> Data Sources (ODBC). If you set up a connection with the same DB Server, username and password and test the connection, you might get some pointers to what is wrong.
If the above doesn't provide you with an answer, I'd try to go through the steps described here:
http://blog.sqlauthority.com/2009/05/21/sql-server-fix-error-provider-named-pipes-provider-error-40-could-not-open-a-connection-to-sql-server-microsoft-sql-server-error/
And if that fails, take a look at this - which is apparently only valid when you get SQL Network Interfaces, error: 26
http://blogs.msdn.com/b/sql_protocols/archive/2007/05/13/sql-network-interfaces-error-26-error-locating-server-instance-specified.aspx
This is probably a permission problem.
You need to show us your connection string so we can see how exactly you try to connect to your database.
For example, if you are using Windows authentication, maybe your app runs under different accounts on both machines - and the account on the other computers has permission to access the database, but the account on the database server has not.
Have you checked the if the protocols you are using are enabled on the SQL Server e.g.
C:\Windows\System32\cliconfg.exe -- 64 bit version
C:\Windows\SysWOW64\cliconfg.exe -- 32 bit version
or check SQL Server Configuration Manager 'SQL Server Native Client *' tabs.
This is only applicable if you do not use Windows Authentication, else read the post about priviliges from Christian Specht - in this case I agree.
The fact that you can connect from another PC on the network means that all you database settings, user accounts and permissions are probably set up correct.
It seems there might be a issue with the way the server resolves localhost, as it will try to resolve the Data Source to localhost because AXELS = localhost on that machine.
Have a look at your hosts file and see if there's any funny pointers except for the default.
Located in C:\Windows\System32\drivers\etc
There should be an entry: 127.0.0.1 localhost

Easily switching ConnectionStrings on publish to Azure

I'm currently building an Azure Web Role. I am testing this project against a local database server on localhost. Then, when confident that the project is working, I publish it to Staging on Windows Azure.
However, I also have to remember to change the connection string to point to the live SQL server on SQL Azure before deploying, and then change it back to localhost afterwards.
Is there any nice way to automate this, or perhaps a different process to take to avoid the issue altogether? For example is there a way to have a configuration file for Azure that isn't updated with every deploy?
I ended up just referencing the machine name and whether or not I was using Azure, dynamically switching the ConnectionString I referenced accordingly.

Categories

Resources