草庐IT

4Connection

全部标签

c# - 在C#应用程序中,DB Connection应该创建一次,还是每次执行SQL语句时创建一次?

在C#应用程序中,OleDBConnection应该创建一次,还是每次执行SQL语句时创建一次?我正在查看其他人编写的C#代码。每个SQL语句之前都会创建一个OleDbConnection对象,该对象的连接字符串指向MDB数据库。每次都创建一个OleDbConnection对象是否合适,或者该对象是否应该在应用程序启动时创建并从那时起使用。 最佳答案 根据BestPracticesforUsingADO.NET:Highperformanceapplicationskeepconnectionstothedatasourceinus

c# - 无法从传输连接读取数据 : The connection was closed error in console application

我在控制台应用程序中有这段代码,它在一个循环中运行try{HttpWebRequestrequest=(HttpWebRequest)WebRequest.Create(search);request.Headers.Add("Accept-Language","de-DE");request.Method="GET";request.Accept="text/html";using(HttpWebResponseresponse=(HttpWebResponse)request.GetResponse()){using(StreamReaderreader=newStreamRead

c# - "opening a connection"实际上是什么意思?

我试图向某人解释为什么数据库连接实现IDisposable,当我意识到我真的不知道“打开连接”实际上是什么意思时。所以我的问题是-c#在打开连接时实际上做了什么?谢谢你。 最佳答案 实际上有两个类涉及实现连接(实际上更多,但我正在简化)。其中之一是IDbConnection您在代码中使用的实现(SQLConnection、NpgsqlConnection、OracleConnection等)。另一个是程序集内部的“真实”连接对象,对您的代码不可见。我们暂时将其称为“RealConnection”,尽管其实际名称因不同的实现而异(例如

c# - 从 ftp 服务器下载文件时为 "The underlying connection was closed"

我想从ftp服务器下载文件。我写了下面的代码来从ftp下载文件publicvoiddownloadFile(stringFTPAddress,stringfilename,stringusername,stringpassword,stringdestFile){try{FtpWebRequestrequest=FtpWebRequest.Create(FTPAddress+filename)asFtpWebRequest;request.Method=WebRequestMethods.Ftp.DownloadFile;request.Credentials=newNetworkCr

c# - TCP 错误代码 10061 : No connection could be made because the target machine actively refused it

很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visitthehelpcenter.关闭9年前。Couldnotconnecttonet.tcp://localhost:5051/user.Theconnectionattemptlastedforatimespanof00:00:02.0600206.TCPerrorcode10061:Noconnectioncouldbemadebecausethetargetmachineactivelyrefusedit127.0.0.1:5051.

c# - SignalR 2.1.0 : The connection has not been established

我有一个ASP.NETWeb应用程序,其中包含一个简单的HTML页面和一些通过SignalR进行通信的JavaScript。那很好用。现在,我正在尝试从另一个项目(在同一解决方案中)调用Hub上的方法并使用.NETSignalrClientApi:varconnection=newHubConnection("http://localhost:32986/");varhub=connection.CreateHubProxy("MessageHub");connection.Start();hub.Invoke("SendMessage","","");最后一行导致InvalidOpe

c# - 执行非查询 : Connection property has not been initialized.

下午,所以我已经在这个问题上研究了几个小时,但无法真正克服最后一个障碍。下面是我正在编写的这个程序的代码:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Diagnostics;usingSystem.Data;usingSystem.Data.SqlClient;usingSystem.Configuration;namespaceTest{classProgram{staticvoidMain(){EventLogalog=newEventLog();

c# - Connection.open 无限期挂起,不抛出异常

当我尝试执行以下代码时,程序无限期挂起。我不知道为什么,似乎还有其他Unresolved话题。不过,如果无法访问IP\网站,则它会按预期工作。privatevoidDoStuff(){stringconnectionString="DataSource=www.google.com;ConnectionTimeout=5";using(SqlConnectionconnection=newSqlConnection(connectionString)){connection.Open();//HangshereindefinitelyConsole.WriteLine("Test");

c# - httpWebRequest(底层连接已关闭 : The connection was closed unexpectedly. )

我正在开发一个C#应用程序,它记录来自网络服务器的数据。它向网络服务器发送以下发布请求并等待响应。//////FunctionforobtainingtestCgidata/////////privatestringHttpmyPost(stringParameters){stringstr="Noresponse";HttpWebRequestrequest=(HttpWebRequest)WebRequest.Create(uriTestCGI);request.Method="POST";byte[]bytes=Encoding.UTF8.GetBytes(Parameters)

c# - Web Config.Connection String 中的相对路径引用

是否可以在web.config中的连接字符串、attachDbFileName属性中指定相对路径引用?例如,在我的数据库位于App_data文件夹中,我可以轻松地将AttachDBFilename指定为|DataDirectory|\mydb.mdf和|Datadirectory|将自动解析为正确的路径。现在,假设web.config文件位于A文件夹中,但数据库位于B\App_data文件夹中,其中A和B文件夹位于同一文件夹中。无论如何使用相对路径引用来解析正确的路径? 最佳答案 我在以下场景中遇到了同样的问题:我想使用与集成测试中