【问题标题】:How to connect my webrole app (vb.net) to my sql azure database?如何将我的 webrole 应用程序 (vb.net) 连接到我的 sql azure 数据库?
【发布时间】:2012-06-29 01:01:57
【问题描述】:

我正在 Web 表单中创建一个名为 SGS 的新应用程序 (webrole)。此应用程序正在使用 vb.net 构建。

我正在 Windows 7 中开发应用程序并已将其部署到 Windows azure。

每次我需要更改应用程序中的某些内容时,我都会在本地进行更改,然后将其再次发布到我的生产环境中(我知道在 azure 中暂存环境,但我更喜欢生产环境)。

应用程序位于起点,现在我需要将其连接到我在 SQL Azure 中的数据库。

我在 SQL Azure 上构建了一个名为 SGS 的新数据库,我想将我的应用程序连接到它。

我希望即使我在本地环境中,我的应用程序也只连接到我的 sql zure 数据库。这样我就不需要本地电脑上的任何数据库了。

我不知道该怎么做.....

天蓝色上的连接字符串(ado.net)是:

Server=tcp:mwjw08qhju.database.windows.net,1433;Database=SGS;User ID=pr@mwjw08qhju;Password=myPassword;Trusted_Connection=False;Encrypt=True;

我的 webconfig 文件作为这个信息:

<xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.diagnostics>
    <trace>
      <listeners>
        <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
          <filter type="" />
        </add>
      </listeners>
    </trace>
  </system.diagnostics>
  <connectionStrings>
    Server=tcp:mwjw08qhju.database.windows.net,1433;Database=SGS;User ID=pr@mwjw08qhju;Password=myPassword;Trusted_Connection=False;Encrypt=True;


    <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
 <!--   <add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial 
        Catalog=aspnet_1db0ca8ec36d4ba1852e5e4ec9947660;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />-->


    <add name="DefaultConnection" connectionString=" <add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet_1db0ca8ec36d4ba1852e5e4ec9947660;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
    <add name="aspnet_1db0ca8ec36d4ba1852e5e4ec9947660Entities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\SQLEXPRESS;initial catalog=aspnet_1db0ca8ec36d4ba1852e5e4ec9947660;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <system.web>
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login.aspx" timeout="2880" />
    </authentication>
    <membership defaultProvider="DefaultMembershipProvider">
      <providers>
        <clear />
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
        <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
      </providers>
    </membership>
    <profile defaultProvider="DefaultProfileProvider">
      <providers>
        <clear />
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
        <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
      </providers>
    </profile>
    <roleManager enabled="false" defaultProvider="DefaultRoleProvider">
      <providers>
        <clear />
        <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
        <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
        <add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
      </providers>
    </roleManager>
    <sessionState mode="InProc" customProvider="DefaultSessionProvider">
      <providers>
        <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
      </providers>
    </sessionState>
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
</configuration> 

我需要改变什么来完成这个?

非常感谢。

【问题讨论】:

    标签: vb.net azure azure-sql-database webrole


    【解决方案1】:

    此设置应该完全符合您的要求。如果您想在本地运行时连接到 SQL Server 而在部署时连接到 SQL Azure,那么它只是稍微复杂一些。

    不过,要从本地计算机连接到 SQL Azure,您需要有一个允许流量到达 SQL Azure 的防火墙规则。具有讽刺意味的是,post right below yours in Stack Overflow 的响应应该可以帮助您执行此操作(如果您还没有这样做的话)。

    如果您设置了防火墙规则,但仍然遇到问题,请回复有关不工作的更多细节、错误消息等。

    【讨论】:

      【解决方案2】:

      将服务和默认连接字符串更改为您从 Azure SQL 门户收到的连接字符串。

      所以你会得到这个:

      <add name="ApplicationServices" connectionString="mwjw08qhju.database.windows.net,1433;Database=SGS;User ID=pr@mwjw08qhju;Password=myPassword;Trusted_Connection=False;Encrypt=True;" providerName="System.Data.SqlClient" />
      

      希望有帮助

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-05-26
        • 1970-01-01
        • 2014-11-15
        • 1970-01-01
        • 2021-04-23
        相关资源
        最近更新 更多