gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 04:38:25 24 4
gpt4 key购买 nike

我有一个 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com