问题
I need to be moving an existing Asp.NET application to Azure, where I've also set up a virtual machine hosting sql server. Now, I obviously don't want to keep deploying all the time, and I haven't even configured Azure for the application to exist within yet. I only want to make sure I can get the application to connect to the sql server instance on the virtual machine.
I'm a complete newbie when it comes to Azure. So I've absolutely no idea what I'm doing, but I'm using tutorials and good ol' Google to try and figure it all out.
I have the connection string in my web.config formatted the way listed on this tutorial, as follows:
<add name="AzureSqlServer" connectionString="Data Source=tcp:[internal-IP];
Initial Catalog=TestDb;User ID=[sql-user];Password=[sql-pass];Encrypt=true;
Trusted_Connection=false;TrustServerCertificate=true"
providerName="System.Data.SqlClient" />
This doesn't connect on its own, so there's obviously something else I have to do. Now, the tutorial follows this section with several steps which all require the Azure SDK to be installed, including setting up the Web Role to connect to the Azure-hosted VM with SQL Server on it. That's all fine and dandy, but there's one little tiny thing it doesn't say anything about:
As it turns out, the Azure SDK is only compatible with Windows Vista and up. So, I can do a Win7 virtual machine, but it would take a few extra days.
Are there any other ways to hook up an Asp.NET Web Application to an Azure-hosted SQL Server Virtual Machine, other than using the Azure SDK?
回答1:
You mentioned not knowing anything about Azure, so checking out the tutorials at www.windowsazure.com is a great place to start, especially if you're attempting to launch a production application into an environment you know little about.
Having said that: If your SQL Server is running in a VM, and that VM is part of a different deployment from your asp.net app (e.g. you used something like a web role, or Azure Web Sites), than you can not use your SQL Server's internal IP address, since you'd have no access to that IP address (each deployment lives in its own private network). Your options would be:
- If you deployed your website to Azure Web Sites, you'd reach your SQL Server VM through its public endpoint (you'd need to create that endpoint, called an input endpoint, with port 1433 opened). So it would be yoursqldeployment.cloudapp.net:1433.
- If you deployed to a Cloud Service with a web role (yourwebapp.cloudapp.net), you could do the same thing as with Web Sites, or you could create a Virtual Network between your Cloud Service and your SQL Server Virtual Machine deployment.
- If you deployed your website to a virtual machine in the same deployment as your SQL Server VM (and it doesn't sound like you did that), then you can directly communicate with SQL Server via its internal IP address or DNS name.
And, as long as everything is in the same data center, you won't have any data traffic between your website and your database going outside the data center.
One more thing, regarding Azure SDK: While you may need the SDK for accessing storage and other services, you don't need the SDK for communicating with another virtual machine.
来源:https://stackoverflow.com/questions/18662610/connecting-existing-asp-net-application-to-azure-sql-server-vm-without-sdk