我Transaction Binding=Explicit Unbind在这里建议使用连接字符串,因为我也使用TransactionScope超时.问题是连接在处理后似乎没有关闭,最终连接池中没有可用的连接.当我修改TransactionTimeoutIssueDemo(请参阅链接)并在循环中运行TransactionScopeTest()(使用显式的unbind连接字符串)足够多次以使用连接池中的所有可用连接时,我得到了相同的结果.池中连接的默认值为100,但可以使用该设置更改此值Max Pool Size =10.使用显式解绑绑定时似乎不会释放连接,即使SqlConnection和TransactionScope都与using条款.任何人都知道如何处理这个?
我想知道是否有一种优雅的方法来检查数据库是否存在?简而言之,如何测试db连接字符串的连接?
谢谢
SQL Express 2005 正在本地运行。我有一个在同一台机器上运行的另一个人编写的项目。我想做的就是连接到它,不会那么难吧?
这是我在旧的经典 ASP 代码中用来访问运行在同一实例上的另一个数据库的代码:
Provider=SQLOLEDB;Data Source=MYLAPTOP\MSSMLBIZ;Persist Security Info=True;User ID=TestUser;Password=letmein;Initial Catalog=TestDB
但是尝试一个版本会使 .net 代码在他使用 SQLServer 驱动程序编写时抛出一个不稳定的问题,因此它不喜欢 Provider 的东西。
这是他的代码中的原始连接字符串:
服务器=(本地);初始目录=数据库;用户 ID=用户;密码=密码;
我去过http://www.connectionstrings.com/sql-server-2005并从那里尝试了几个选项,这些都得到“SQL Server 不存在或访问被拒绝”(多么可爱的混合错误消息)是!):
我已经在 SQL Express 中为 MyLaptop/IUSR_MyLaptop、MyLaptop/ASPNET、MyLaptop/IWAM_MyLaptop 创建了登录名,并授予它们对我的数据库的所有读/写权限,并将其默认数据库设置为 TheDatabase。
我到底做错了什么,我该如何进一步调试问题?
更新:特别感谢 Chris 的所有指点,最终到达那里,如果您遇到类似问题,请阅读所有评论,其中有很多链接和有关如何追踪它们的提示。
asp.net connection-string database-connection sql-server-express
我试图在运行时更改位于Servicehost的App.Config中的connectionstring中的数据库名称,然后在连接到另一个数据库后重新启动它.这样可以正常工作,但前提是应用程序关闭多秒钟.关闭应用程序几秒钟似乎清除了ConfigurationManager.Connectionstrings的缓存.问题是由于这个需要的关机时间,我不能在我的应用程序中使用Application.Restart().
这种缓存行为的奇怪之处在于,即使在内存中更新了值(在第二次请求时的示例中),也会正确显示更新后的值.但是当应用程序重新启动时,旧值似乎重新出现.
要验证行为,请创建新的控制台应用程序.
添加App.Config文件
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="DomainDBConnectionString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=InitialDBName;Integrated Security=SSPI;" />
</connectionStrings>
</configuration>
Run Code Online (Sandbox Code Playgroud)
然后将以下代码添加到Main方法
ConfigurationManager.RefreshSection("connectionStrings");
DbConnectionStringBuilder builder = new DbConnectionStringBuilder();
Configuration appConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
builder.ConnectionString = appConfig.ConnectionStrings.ConnectionStrings["DomainDBConnectionString"].ConnectionString;
//print initial value
Console.WriteLine("initial " + (string)builder["Initial Catalog"]);
//change value
builder["Initial Catalog"] = "ChangedDatabaseName";
appConfig.ConnectionStrings.ConnectionStrings.Remove("DomainDBConnectionString");
appConfig.ConnectionStrings.ConnectionStrings.Add(new ConnectionStringSettings("DomainDBConnectionString", builder.ConnectionString));
appConfig.ConnectionStrings.SectionInformation.ForceSave = true;
appConfig.Save(ConfigurationSaveMode.Full);
ConfigurationManager.RefreshSection("connectionStrings");
Console.ReadLine();
DbConnectionStringBuilder builder2 = new DbConnectionStringBuilder();
Configuration appConfig2 = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
builder2.ConnectionString = appConfig.ConnectionStrings.ConnectionStrings["DomainDBConnectionString"].ConnectionString;
Console.WriteLine("changed " + (string)builder2["Initial Catalog"]);
Console.ReadLine();
Run Code Online (Sandbox Code Playgroud)
要重现此行为,您需要运行应用程序(通过按F5)并关闭它.之后,solutionname.exe.config文件将显示修改后的值.如果您再次运行该应用程序(这次双击solvename.exe),如果您在终止应用程序后立即执行此操作,或者等待几秒钟后,您会发现行为上的差异.
在我看来,由于ConfigurationManager.RefreshSection("connectionStrings"),应该重新读取configsection; 但似乎这不像宣传的那样有效.
目前,我正在搜索连接字符串的属性,该字符串可用于以只读模式连接到 Excel 文件。搜索 Google 为我提供了很多连接字符串示例,但我似乎无法在 OleDb 连接字符串的“扩展属性”部分中找到所有可能性的规范。
目前我有这个:
Provider = Microsoft.Jet.OLEDB.4.0; Data Source = D:\Data\Customers.xls; Extended Properties = 'Excel 8.0; Mode=Read; ReadOnly=true; HDR=Yes';
Run Code Online (Sandbox Code Playgroud)
但是......我已经通过示例编写了这个。所以问题: 1. OleDb 连接字符串文档/参考的合适来源是什么?2. 上面的连接字符串是否确实以只读模式连接到Excel文件?
谢谢!
它随 Visual Studio 2010 Ultimate 自动安装。我没有为服务器或任何东西创建任何用户。
我正在使用:
string connectionString = @"Server=.\SQLEXPRESS;Database=SportsStore;Trusted_Connection=yes;";
Run Code Online (Sandbox Code Playgroud)
我收到身份验证失败的错误。所以找到了服务器,但我的凭据是错误的。默认登录名和密码是什么?
编辑:仍然无法正常工作!:(
这是我的连接字符串:
string connectionString = @"Server=.\SQLEXPRESS;Database=SportsStore;Integrated Security=SSPI;";
Run Code Online (Sandbox Code Playgroud)
和错误信息:
无法打开登录请求的数据库“SportsStore”。登录失败。用户“ToshibaLaptop\Sergio”登录失败。
当我们连接到ASP.NET中的数据库时,您必须指定适当的连接字符串.但是,要指定数据的大多数其他实例是在对象内完成的.
例如,为什么我们不能有连接对象,例如:
var connection = new connectionObject(){
DataSource = "myServerAddress",
IntialCatalog = "myDataBase",
UserId = "myUsername",
Password = "myPassword"
}
Run Code Online (Sandbox Code Playgroud)
这比一些键/值字符串要好得多:
Data Source = myServerAddress; Initial Catalog = myDataBase; UserId = myUsername; Password = myPassword;
我能想到的唯一原因是允许在web.config中存储,但是无论如何都没有什么能阻止我们将各个值存储在那里.
我确信有充分的理由,但他们是什么?
我想从Java连接到当前正在从phpMyAdmin管理的数据库。我不拥有数据库运行的服务器。
但是,我想找到该数据库的连接字符串,以便能够使用Java与我的数据库进行通信。
有谁知道如何找到该连接字符串?
我制作了ASP.NET MVC Web应用程序,上传了文件,也上传了数据库,但是在浏览时出现以下错误.
找不到网络路径
我正在使用Entity Framework,这是我的web.config文件中的连接字符串
<connectionStrings>
<add name="[mydatabase]Entities" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=sql.[somedomain].net;initial catalog=[mydatabase name];User ID=[myUsername];Password=[myPassword];MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)
我上传了许多使用IP地址的网站,例如.xxx.xxx.x.xxx作为数据源,但这是第一次使用服务器名称,例如.sql.[somedomain] .net - 我无法获取服务器ip-,所以我不确定这是否会导致错误,或者我是否应该制作一些特殊功能才能使其正常工作.
所以,我问我是否应该使用服务器名称作为数据源,如果没有,那么还有什么可能导致此错误.
这个答案并没有真正帮助.
提前致谢.
更新
如果我ping服务器sql.[somedomain] .net,我得到这个结果
Ping请求找不到主机sql.[somedomain] .net.请检查名称,然后重试.
如果我查看它,我会得到这个结果
***Unknown无法找到sql.[somedomain] .net:不存在的域名
那么这是否意味着 - 确保服务器无法访问.除了联系托管技术支持之外,我还能做些什么吗?
解决了
这是主机提供商错误/配置错误.经过3天的搜索和联系客户支持后,他们意识到这是他们的问题.我要离开这个问题,告诉未来的观众无论如何都要有可靠/知名的托管服务提供商.
我正在尝试将一些数据发布到作为副本集的远程mongodb实例中,但是却收到超时异常消息,提示找不到主机?我也阅读并?connect=replicaSet在连接字符串的末尾添加了内容,但这没有帮助。
这是我的连接字符串
private MongoClient client = new MongoClient("mongodb://10.250.8.1:27017,10.250.8.2:27017,10.250.8.3:27017?connect=replicaSet");
Run Code Online (Sandbox Code Playgroud)
这是抛出的异常:
{"A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = WritableServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : \"1\", ConnectionMode : \"ReplicaSet\", Type : \"ReplicaSet\", State : \"Disconnected\", Servers : [{ ServerId: \"{ ClusterId : 1, EndPoint : \"Unspecified/wsmongodb001:27017\" }\", EndPoint: \"Unspecified/wsmongodb001:27017\", State: \"Disconnected\", Type: \"Unknown\", HeartbeatException: \"MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> …Run Code Online (Sandbox Code Playgroud) c# ×5
sql-server ×4
.net ×2
database ×2
ado.net ×1
asp.net ×1
asp.net-mvc ×1
connection ×1
mongodb ×1
mysql ×1
phpmyadmin ×1
runtime ×1
sql ×1
timeout ×1
transactions ×1
vb.net ×1