sql - 从本地 WCF 连接到 Azure SQL 数据库

标签 sql azure connection-string azure-sql-database

我有一个 WCF Web 服务和本地数据实例在我的本地计算机上完美运行。我已经在 azure 上创建了一个数据库实例,以及如何将 Web 服务连接到它,以确保它在我托管到 Azure 上的 Web 服务之前正常工作。

我已经设置了一个到本地数据库的连接字符串,该字符串现在可以工作,因此我认为我只需要将其更改为新的 azure 连接字符串,但这不起作用。请参阅下面的工作连接字符串与非工作连接字符串以及我如何在 DAL 中实现我的代码。

当前/本地连接字符串

<add name="VervePhaseOneConnectionString" connectionString="Data Source=SNICKERS\SQLEXPRESS;Initial Catalog=VervePhaseTwo;Integrated Security=True"
          providerName="System.Data.SqlClient" />

新的 azure 连接字符串不起作用

  <add name="VervePhaseOneConnectionString" connectionString="Server=tcp:server.database.windows.net,1433;Database=VerveDB;User ID=bradleya@server;Password={passwordString};Trusted_Connection=False;Encrypt=True;Connection Timeout=30;"
      providerName="System.Data.SqlClient" />

使用连接字符串的 DAL 代码

SqlConnection oConn = new SqlConnection();
            oConn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["VervePhaseOneConnectionString"].ConnectionString;
            oConn.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = oConn;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "sp_addSessionPlay";

如有任何帮助,我们将不胜感激。

谢谢。

最佳答案

您的连接字符串对我来说看起来是正确的。但是,要检查它,您可以登录到您的 Azure 帐户并单击 SQL 数据库并查看连接字符串。它将为您提供所需的不同示例。

enter image description here

另外,我假设您已经检查了 Azure 中的防火墙设置?

祝你好运。

关于sql - 从本地 WCF 连接到 Azure SQL 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14462652/

相关文章:

mysql - 在不同于 3306 的端口上配置 webmatrix3 mysql 连接 UI

MySQL 从搜索问题开始

java - 如何通过 Java 使用 Azure 缓存服务(预览版)

sql - 如何避免注入(inject)按运行时值排序查询

node.js - 无需注册应用程序即可进行 Microsoft-Graph API 调用

linux - 如何在 Linux 上让 PGBouncer 在重启时自动启动?

sql-server - SSIS : Unwanted line return on a dynamic connection string

linq-to-sql - 当我将表拖入 dbml 文件时,阻止 LINQ to SQL dbml 更新连接字符串

sql - 如何存储 SQL 查询结果供以后显示

SQL-Select 组合时会出现错误