嗨,我收到了一个错误Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
我已经改变了连接timeout = 60000,在数据库中我的程序在43秒内执行.所以PLZ给了我一些完美的解决方案
谢谢
database sql-server timeout sqlconnection connection-timeout
我看过很多相同主题的帖子。但两者都没有帮助我。我想将 Postgresql 与 CrossPlatform-App 一起使用。稍后我将使用云中的服务器,但为了尝试,我认为使用本地数据库更容易。因此,我已经安装了数据库本身和带有“NuGet”的“npgsql”包,就像 Postgres 人推荐的那样。在连接时总是出现相同的错误后,我将代码简化为一个只有十行代码的控制台应用程序。
namespace SqlTester_ConsolApp
{
class Program
{
static void Main(string[] args)
{
string MyConnection = "Server=127.0.0.1;Port=5432;Database=sample;UserId=Postgresql;Password=zzzzzzzzz;";
try
{
SqlConnection Connection = new SqlConnection(MyConnection);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("---------------------------------------------------------------------");
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
System.Diagnostics.Debug.WriteLine("Ready");
}
}
}
Run Code Online (Sandbox Code Playgroud)
Thenew SqlConnection总是以和System.ArgumentExceptiontell结尾Keyword not supported 'port'。原因很明显,.Net Framework 尝试使用 SQL Server 而不是将我的 String 传递给 npgsql 驱动程序。因此,从字符串中剪切“端口”是没有意义的。
我的问题是如何将字符串解析更改为 Progresql 提供程序?积极地,我没有为那个错误的选择做任何事情,这显然是 .Net Framework 的默认行为的一部分,它要么是错误,要么是打算只支持 MS-Products。
我尝试了一些改变行为的方法。 更新澄清:因为“NpgsqlConnection”的使用对我来说是不可接受的。我的代码应该是独立于提供者的。
正如我在PostgreSQL相关的Docu发现和Npgsql的另一个问题,同样的问题我添加了以下行App.Config控制台应用程序内的文件。
<system.data>
<DbProviderFactories> …Run Code Online (Sandbox Code Playgroud) 我有一个 Vb.net 程序,它查询数据库以获取一堆记录。我不太清楚如何传递参数。下面是我的代码:
Dim connectionString As String
Dim sqlCnn As SqlConnection
Dim sqlCmd As SqlCommand
Dim sql As String
Private Function GetCustomerData() As DataTable
locationdb = "10.0.1.1"
connectionString = ("Data Source=" & locationdb & ";Initial Catalog=TestDB;Persist Security Info=True;User ID=user;Password=password")
sql = ("SELECT lCustomerID,CustomerName,address FROM customers where @active = True...ETC")
sqlCnn = New SqlConnection(connectionString)
Dim CategoryAdapter As New SqlDataAdapter(sql, sqlCnn)
Dim CustomerInfo As New DataSet()
sqlCmd.Parameters.AddWithValue("@StartDate", frmMain.Startdate)
sqlCmd.Parameters.AddWithValue("@EndDate", frmMain.Enddate)
sqlCmd.Parameters.AddWithValue("@Department", "ALL")
sqlCmd.Parameters.AddWithValue("@Active", "1")
sqlCmd.Parameters.AddWithValue("@Visits", "ALL")
CategoryAdapter.Fill(CustomerInfo, "Customers")
Return CustomerInfo.Tables(0)
End Function …Run Code Online (Sandbox Code Playgroud) 是否可以创建一个SqlConnection数组?用于举例;
SqlConnection[] con = new SqlConnection[4];
con[0].ConnectionString = "my connection string";
Run Code Online (Sandbox Code Playgroud)
写这段代码时,它没有错误,但是当你运行它时它会说:
Object reference not set to an instance of an object.
Run Code Online (Sandbox Code Playgroud) c# ×2
sql ×2
arrays ×1
asp.net ×1
database ×1
postgresql ×1
sql-server ×1
timeout ×1
vb.net ×1