use*_*035 6 c# sql asp.net connection-string azure
我正在尝试通过在 Visual Studio 2013 中创建的 ASP.NET WebForms 网站从 MS Azure 上托管的 SQL Server 数据库中读取数据。
我已经在 Web.Config 中存储了连接字符串,并在我的代码隐藏中引用了它。
但是,当我尝试在本地运行 Default.aspx 时,会显示此错误。
这是我的 Web.Config:
<connectionStrings>
<add name="FYPConnectionString1"
connectionString="Data Source=damo.database.windows.net??;Initial Catalog=Ballinora_db;
Persist Security Info=True; User ID={Username};Password={Password};" />
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)
我从连接字符串中删除了“MultipleActiveResultsSets=False”以查看错误是否停止,但现在显示“加密”错误。
因此错误出现在连接字符串的密码部分之后的下一项。密码是否与问题有关?
此外,此用户名和密码是必需的,它们是 Azure 门户中显示的服务器管理员登录详细信息吗?
这里也是代码隐藏:
private void bindRepeater()
{
string constr = ConfigurationManager.ConnectionStrings["FYPConnectionString1"].ConnectionString;
//-- assuming Azure connection string stored in ConnectionString config in Web.Config as YourConnString
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT Name FROM Users", con))
{
cmd.CommandType = CommandType.Text;
con.Open();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
repTest.DataSource = dt;
repTest.DataBind();
con.Close();
}
}
}
protected void btnDisplay_Click(object sender, EventArgs e)
{
this.bindRepeater();
}
Run Code Online (Sandbox Code Playgroud)
MultipleActiveRe\xe2\x80\x8c\xe2\x80\x8b\xe2\x80\x8c\xe2\x80\x8bsultSets 的默认值为 False。
\n\n而如果不需要该函数,直接退出(删除)\n\' MultipleActiveRe\xe2\x80\x8c\xe2\x80\x8b\xe2\x80\x8c\xe2\x80\x8bsultSets=False \'连接字符串。
\n\n因为默认值是 false。如果你想要 false,你不需要故意写它。
\n\n当我们在第一个 SQL 连接的 SqlDataReader 的 while 循环内打开第二个 SQL 连接时,我们需要 MultipleActiveRe\xe2\x80\x8c\xe2\x80\x8b\xe2\x80\x8c\xe2\x80\x8bsultSets 的函数。
\n\n然而,为什么 \' MultipleActiveRe\xe2\x80\x8c\xe2\x80\x8b\xe2\x80\x8c\xe2\x80\x8bsultSets=False \' 被识别为错误语法仍然是个问题。
\n\n更新-
\n\n这就是为什么我很好奇为什么它是错误的。我认为 MultipleActiveRe\xe2\x80\x8c\xe2\x80\x8b\xe2\x80\x8c\xe2\x80\x8bsultSets 和 Encrypt 的语法没有问题。
\n\n这是我在 Web.Config 中的连接字符串:
\n\n<connectionStrings>\n <add name="GreenLeaf" connectionString="Server=tcp:greentree.database.secure.windows.net,1433;Database=greentea;User ID=greenusers@greentree;Password=abc123;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;MultipleActiveResultSets=True;"/>\n</connectionStrings>\nRun Code Online (Sandbox Code Playgroud)\n\n与你的不同之处在于,
\n\n1) tcp\n2) secure\n3) @greentree(服务器名称 greentree 以及 ID,如 (greenusers@greentree)\n4),无提供程序
\n\n“安全”是 Azure 自动提供安全连接的新功能,您可以在互联网上找到相关信息。
\n\n检查服务器的防火墙,然后尝试按上述几点进行尝试。
\n\n使用管理员 ID 是正确的,但在安全方面,您需要为具有有限角色和权限的外部用户创建额外的登录名和用户。
\n\n可以通过Azure Portal连接到Azure服务器(数据库)吗?视觉工作室?服务器管理工作室?
\n\n当您进入 Server Management Studio 时,在弹出的连接窗口中,\n有“服务器名称”。在那里输入“greentree.database.windows.net”并尝试使用您的管理员凭据登录。
\n\n或者您可以在 Web.Config 中不使用连接字符串但使用纯代码连接到 Azure 服务器吗?
\n\n如果可能,请更新异常的屏幕截图,而不仅仅是文本。
\n\n最后,我相信您很清楚,为了安全起见,我们需要稍后对连接字符串进行加密。
\n| 归档时间: |
|
| 查看次数: |
8921 次 |
| 最近记录: |