connection-string 相关问题

包含连接服务所需信息的字符串,通常是数据库。

Scaffold-DbContext 与 appsettings.json 中的 ConnectionString 时出错,但如果手动指定相同的连接字符串则有效

我正在尝试从现有数据库反向创建 C# 代码。 如果我手动输入连接字符串并键入命令: Scaffold-DbContext '数据源=MyServer;初始目录=MyCatalog;

回答 1 投票 0

MongoDB 集群 VSCode 连接

我创建了一个 MongoDB 集群。 在“网络访问”选项卡中添加了我的 IP 地址。 然后我转到 VSCode 并添加了 MongoDB 扩展。 我单击“连接”,然后插入连接字符串…

回答 1 投票 0

在 C# 程序中运行的复杂 SQL 查询会超时,除非我首先在 SSMS 中运行该查询

如果我第一次在 SSMS 中运行相同的查询,查询将在 C# 程序中运行(无超时)。在我在 SSMS 中运行查询之前,数据库似乎没有初始化、加载等。 这只会发生...

回答 1 投票 0

MySql 连接字符串中的连接生命周期=0

连接字符串中的 Connection Lifetime=0 究竟意味着什么?

回答 4 投票 0

使用 ADODB 连接到两个(或更多)共享点列表

我可以通过这种方式使用 ADODB 连接到 SharePoint 列表: Dim objCon 作为新的 ADODB.Connection objCon.Open“Provider=Microsoft.ACE.OLEDB.12.0;WSS;IMEX=2;RetrieveIds=Yes;DATABASE=mysite/documents;LIST...

回答 3 投票 0

nhibernate 配置未连接到数据库

我遇到一个问题: 建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例...

回答 1 投票 0

使用老式 ASP.NET / C# 后端和 web.config - 我需要一个动态连接字符串

我的 web.config 中有以下连接字符串: 我的web.config中有以下连接字符串: <add name="ConvMapping.Properties.Settings.ifl" connectionString="Data Source=serverInfo;Initial Catalog=database;Persist Security Info=True;User ID=userid;Password=password" providerName="System.Data.SqlClient" />` 现在的问题是我们必须根据选择使用数据库。 所以,例如我想做类似的事情: Data Source=serverInfo;Initial Catalog=Grant_database;Persist Security Info=True;User ID=userid;Password=password 或 Data Source=serverInfo;Initial Catalog=Wilson_database;Persist Security Info=True;User ID=userid;Password=password 其中所有数据库都将以格式命名 County_database。 在 ASP.NET 中,为了现在获取该字符串,我执行以下操作: ConnectionString="<%$ ConnectionStrings:ConvMapping.Properties.Settings.codes %>" 另一种选择是在 web.config 中为所有可能的实例添加连接字符串,但是我不确定如何在内联或代码隐藏区域中执行逻辑来调用适当的连接字符串,并对其进行初始化. 我想到的一种方法是在 switch-a-roo 后面编写代码...... 在网络配置中执行: Data Source=serverInfo;Initial Catalog={0}_database;Persist Security Info=True;User ID=userid;Password=password 然后在 .aspx 中执行以下操作: ConnectionString="<%# GetConnectionString() %>" 最后在后面的代码中做类似的事情: protected string GetConnectionString() { var databaseName = string.Format(Properties.Settings.Default.codes, Request.QueryString["County"]); return databaseName ; } 问题是我收到以下错误: ConnectionString 属性尚未初始化 非常感谢对此的任何帮助。 我使用以下技术:C#、ASP.NET、SQL Server,该程序已有大约 13 年历史,所以有点过时。 string.Format()计划很好,只要您不允许用户为此输入任意文本即可。问题就是所谓的“蜂蜇”: <%# 这意味着使用数据绑定,类似于 Eval() 表达式,并且像其他蜜蜂蜇伤一样,在页面生命周期中发生得太晚了。 相反,您需要完全省略 ConnectionString 文件中的 .aspx 属性,并将数据源的连接字符串设置为后面代码的一部分。 因此,如果您当前有这样的数据源: <asp:sqldatasource id="SqlDataSource1" SelectCommand="SELECT ... FROM ..." ConnectionString="<%$ ConnectionStrings:ConvMapping.Properties.Settings.codes %>" runat="server"/> 您可以完全删除该属性: <asp:sqldatasource id="SqlDataSource1" SelectCommand="SELECT ... FROM ..." runat="server"/> 然后您的页面加载将包括以下内容: SqlDataSource1.ConnectionString = string.Format(Properties.Settings.Default.codes, Request.QueryString["County"]);

回答 1 投票 0

如何处理 Postgresql URL 连接字符串密码中的特殊字符?

使用以下格式的 Postgresql URL 连接字符串: postgresql://用户:secret@localhost 如何处理该字符串中的特殊字符(例如 $),以便当我

回答 4 投票 0

从外部 XML 文件读取连接字符串

在我的 ASP.NET MVC 项目(在 .NET 4.8 上)中,我有一个带有以下工作连接字符串的 web.config: 在我的 ASP.NET MVC 项目(在 .NET 4.8 上)中,我有一个带有此工作连接字符串的 web.config: <connectionStrings> <add name="SystemConnectionString" connectionString="Server=10.10.10.10; Port=1000; Database=SampleDB; User Id=user1; Password=aaa;" providerName="Npgsql" /> </connectionStrings> 我正在尝试将其从 web.config 中删除,想法是将其放入本地 XML 文件中,从而避免将此信息推送到云存储库。 我已经制作了这个 XML(没有 providerName="Npgsql",我稍后会提到): <connectionStrings> <add name="SystemConnectionString" connectionString="Server=10.10.10.10; Port=1000; Database=SampleDB; User Id=user1; Password=aaa;" /> </connectionStrings> 我创建了这段代码: public class SystemEntities : DbContext { private static SystemEntities instance; public static SystemEntities Instance() { lock (typeof(SystemEntities)) if (instance == null) instance = new SystemEntities(); return instance; } public SystemEntities() : base(nameOrConnectionString: GetConnectionString()) { this.Configuration.LazyLoadingEnabled = false; this.Configuration.ProxyCreationEnabled = false; } private static string GetConnectionString() { string filename = "ConnectionStrings.xml"; // Get the path to the XML file containing connection strings string documentPath = ConfigurationManager.AppSettings["keysFolder"]; //keysFolder is set at web.config string xmlFilePath = Path.Combine(documentPath, filename); if (!File.Exists(xmlFilePath)) throw new FileNotFoundException("Error: file not found"); // Load the XML file XDocument doc = XDocument.Load(documentPath + filename); // Retrieve the connection string by name string connectionString = doc.Descendants("add") .Where(a => a.Attribute("name")?.Value == "SystemConnectionString") .Select(a => a.Attribute("connectionString")?.Value) .FirstOrDefault(); if (string.IsNullOrEmpty(connectionString)) throw new ConfigurationErrorsException("Error: connection strings not found"); return connectionString; } } 当我尝试上面的代码连接到 postgres 数据库时,我收到此错误: 28000:主机“10.10.10.10”、用户“user1”、数据库“template1”没有 pg_hba.conf 条目,无加密 在我看来,连接字符串不正确,因此导致了这种情况。另外,如果我将数据库从 pg_hba.conf 更改为 all,那么我就可以连接到数据库。 查看此代码时,我确实注意到 providerName="Npgsql" 未包含在从 XML 文件获取的连接字符串中,这可能是导致此问题的原因。我尝试将 Npgsql 添加到字符串中,但没有成功。 有人可以评论一下吗? 我不知道您的项目中是否有多个连接字符串,并且您只希望其中一些位于外部文件中。但是,如果所有连接字符串(或总共只有这一个)都位于外部文件中,则无需编写手动读取该文件的代码。 ASP.NET 支持使用 web.config 属性将一个 configSource 文件拆分为多个文件。在您的示例中,您的 web.config 看起来像这样: <?xml version="1.0"?> <configuration> <connectionStrings configSource="ConnectionStrings.xml" /> </connectionStrings> ConnectionStrings.xml 将包含 connectionStrings 的根元素,它将添加示例中的连接字符串: <?xml version="1.0" encoding="utf-8" ?> <connectionStrings> <add name="SystemConnectionString" connectionString="Server=10.10.10.10; Port=1000; Database=SampleDB; User Id=user1; Password=aaa;" providerName="Npgsql" /> </connectionStrings> 来源:web.config 中连接字符串的终极指南

回答 1 投票 0

如何连接Somee.com上的ASP.NET Web API for SQL Server数据库?

站点 SOMEE 发出此类型的字符串以连接到 SQL Server: 工作站 id=xxx.mssql.somee.com;数据包大小=4096;用户 id=xxxx;pwd=xxxx;数据源=xxxx.mssql.somee.com;坚持安全

回答 1 投票 0

如何从 VB.NET Windows 应用程序修改 app.config 文件中的 ConnectionString?

我想更改 app.config 文件中编写的应用程序的连接字符串。我喜欢直接从我的应用程序更改连接字符串。 我的 app.config 如下所示: 我想更改写在 app.config 文件中的应用程序的连接字符串。我喜欢直接从我的应用程序更改连接字符串。 我的 app.config 看起来像: <?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> ... <connectionStrings> <add name="ApplicationName.My.MySettings.ConnectionS" connectionString="Data Source=xxx;Initial Catalog=xxx;User ID=xxx;Password=xxx" providerName="System.Data.SqlClient" /> </connectionStrings> <appSettings> <add key="Test" value="/" /> </appSettings> </configuration> 我可以使用以下代码在 appSettings 中进行更改: Dim config As System.Configuration.Configuration = System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None) config.AppSettings.Settings("Test").Value = "New value" 但是在安装应用程序时进行调试时我无法在 connectionStrings 中进行更改: Dim config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None) Dim connectionStringsSection = DirectCast(config.GetSection("connectionStrings"), ConnectionStringsSection) connectionStringsSection.ConnectionStrings("ApplicationName.My.MySettings.ConnectionS").ConnectionString = "New connection string" config.Save() ConfigurationManager.RefreshSection("connectionStrings") 要在代码中更改它,请尝试以下操作; Dim con1 = ConfigurationManager.ConnectionStrings("connection1") Dim con2 = ConfigurationManager.ConnectionStrings("connection2") “connection1”和“connection2”是 app.config 中连接字符串的名称。 Dim c As System.Configuration.Configuration = ConfigurationManager.OpenExeConfiguration(System.Reflection.Assembly.GetExecutingAssembly().Location) Dim section As ConnectionStringsSection = DirectCast(c.GetSection("connectionStrings"), ConnectionStringsSection) section.ConnectionStrings("Services.My.MySettings.hassanConnectionString").ConnectionString = createCnxString() c.Save() Private Function createCnxString() As String Dim builder As New System.Data.SqlClient.SqlConnectionStringBuilder builder("Data Source") = datasourceTxt.Text builder("Integrated Security") = True builder("Initial Catalog") = "XXXX" builder("User ID") = usernameTxt.Text builder("Password") = passwordTxt.Text Return builder.ConnectionString End Function

回答 2 投票 0

localhost 和 (LocalDb)/MSSQLLocalDB 之间的 SQL 区别

我注意到我使用了连接字符串来迁移身份数据库。无论我做什么,我都找了又找,但我找不到数据库。所以我重新评估了我的连接字符串并注意到......

回答 2 投票 0

Excel 2013 的 OLEDB 连接字符串

我正在尝试将旧连接字符串调整为 Excel 2013 文件 (.xlsx) 的 Excel 2007 文件 这是我的旧的: strConnectionString = string.Format( “提供商=Microsoft.ACE.OLEDB.12.0;D...

回答 2 投票 0

我不明白 DbConnectionString 中的Password={0}

我需要将程序从一台旧服务器转移到另一台新服务器,以使程序保持几个月的运行状态。 但它不会开始。 在 Program.exe.config.deploy 中我找到了代码: 数据来源=SER...

回答 1 投票 0

多步OLE DB操作生成错误

我在将数据插入 Access 2003 .mdb 数据库时遇到问题。 这个解决方案对我不起作用! 例外: 多步 OLE DB 操作 产生的错误。检查每个 OLE DB 斯塔...

回答 2 投票 0

在 Visual Studio 2022 版本 17.5 中,我面临 ConnectionString 问题

在 Visual Studio 2022 版本 17.5 中,连接字符串会在 Web.config 文件中重复重新生成。每当我删除一个对象(例如存储过程)时,它都会生成一个新的连接字符串

回答 1 投票 0

如何在Visual Studio中添加两个连接字符串?

如何在 Visual Studio 中将 2 个数据库连接字符串写入 app.config? 狐狸的例子 数据源=devsql;初始目录=池;最大池大小=1000;MultipleActiveResultSets=True 我想补充一下

回答 1 投票 0

C# 独立应用程序直接远程访问 MySQL 到托管服务器

根据我的知识,我对 Putty、SSH、DDNS 等进行了大量研究,将动态 IP 从 My PC C# 独立应用程序连接到托管的 MySQL 数据库。由于它是动态IP,所以我...

回答 1 投票 0

建立与 SQL Server 的连接时发生网络相关或特定于实例的错误 [已关闭]

我在 somee.com 上部署了我的 asp.net Web 应用程序,每当我登录到该网站 (ipc.somee.com) 时,它都会给我一个与网络相关的错误,例如: 发生与网络相关或特定于实例的错误...

回答 1 投票 0

hasura cloud 的 MySQL 数据库连接错误

我使用的是hasura云环境。对于 MySQL 数据库,我使用 MySQL Workbench 并创建了一个数据库。我想在 hasura 环境中使用这个数据库。 MySQL 服务器已启动并运行在...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.