gpt4 book ai didi

sql-server - SQL Server 连接任意返回 233 或 18456 错误代码

转载 作者:行者123 更新时间:2023-12-03 03:08:35 25 4
gpt4 key购买 nike

在尝试针对 SQL Server 2008 Express 实例测试无效的连接字符串时,我发现了这种奇怪的行为:指定无效的 Initial Catalog 会引发 SQLException,其编号为有时是 233,有时是 18456。

代码可以更好地说明它。

// The following connection string has a purposely incorrect initial catalog:
string invalidConnString = @"Data Source=.\SQLEXPRESS;Initial Catalog=INVALID_DATABASE_NAME;User Id=dummyUser;Password=dummyPassw;";

SqlConnection connection = new SqlConnection(invalidConnString);

try
{
connection.Open();
}
catch (SqlException sex)
{
Console.WriteLine(sex.Number); // I "randomly" get either 233 or 18456
throw;
}
finally
{
connection.Close();
}

联机丛书中的 system error codes 指定

  • 233 - 已成功与服务器建立连接,但在登录过程中发生错误。 (提供程序:共享内存提供程序,错误:0 - 管道的另一端没有进程。)
  • 18456 - 用户“%.*ls”.%.*ls 登录失败

我认为两者都有不同的表达方式:登录失败。但是,为什么失败不一致呢?

最佳答案

温贝托,

这是使用 SQL Express 时非常常见的问题,根本原因是 SQL Express 默认打开 AUTO_CLOSE 数据库选项。当数据库的所有用户关闭时,数据库将被关闭并干净地关闭。当用户下次登录时,如果数据库重新打开,则无法快速验证用户对该数据库的权限。

AUTO_CLOSE 还有其他副作用,它会刷新过程缓存,并且通常可能导致更高的 CPU 成本。

低调的命令是你的 friend 。

ALTER DATABASE DBNAME SET AUTO_CLOSE OFF

http://msdn.microsoft.com/en-us/library/bb522682.aspx

关于sql-server - SQL Server 连接任意返回 233 或 18456 错误代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3473457/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com