已解决:这不是 SQL Server 的问题,而是不断调用自身的递归函数。/面霜
我目前正在运行 SQL Server 2005 并使用下面的代码。它所做的只是从 SQL Server 获取日期和时间,并且运行良好。
protected internal static string GetDateAndTime()
{
string strDate = null;
string strSQL = null;
// connect to the database and execute our SQL command
strSQL = "SELECT GETDATE() AS THEDATE";
using (SqlConnection sqlConn = new SqlConnection(Constants.CONNECTION_STRING))
{
using (SqlCommand sqlCmd = new SqlCommand(strSQL, sqlConn))
{
sqlConn.Open();
using (SqlDataReader sqlReader = sqlCmd.ExecuteReader())
{
if (sqlReader.HasRows)
{
while (sqlReader.Read())
{
// assign query returned row values
strDate = sqlReader["THEDATE"].ToString();
}
}
}
}
}
}
升级到 SQL Server 2012,现在出现错误。(惊喜!)代码在这一行停止运行。
using (SqlDataReader sqlReader = sqlCmd.ExecuteReader())
错误是:
-StackOverflowException was unhandled
-An unhandled exception of type 'System.StackOverflowException' occurred in System.Data.dll
-Make sure you do not have an infinite loop or infinite recursion.
请注意,除了将连接字符串指向新的 SQL Server 2012 数据库之外,我没有更改任何代码。
请求的信息,堆栈跟踪:
[External Code]
MyProject.exe!MyProject.Database.GetDateAndTime() Line 173 C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.Database.GetDateAndTime() Line 189 + 0x8a bytes C#
MyProject.exe!MyProject.frmSwitchboard.VerifyUserExists() Line 230 + 0x9 bytes C#
MyProject.exe!MyProject.frmSwitchboard.MyProjectPreLoad() Line 136 + 0xd bytes C#
MyProject.exe!MyProject.frmSwitchboard.frmSwitchboard_Load(object sender = {MyProject.frmSwitchboard}, System.EventArgs e = {System.EventArgs}) Line 68 C#
[External Code]
MyProject.exe!MyProject.Program.Main() Line 18 C#
[External Code]
请求的信息,Constants.CONNECTION_STRING:*尝试同时使用...
1. protected internal static string DATABASE_CONNECTION_STRING = @"Data Source=DBSTEST;Initial Catalog=restored 02-04-2013;User ID=sa; UID=sa;PWD=blah;Persist Security Info=True";
2. protected internal static string DATABASE_CONNECTION_STRING = @"Data Source=DBSTEST;Initial Catalog=restored 02-04-2013;User ID=sa;UID=sa;PWD=blah;Connect Timeout=300";
请求的信息,函数 VerifyUserExists():
private DataTable VerifyUserExists()
{
string strSQL = null;
DataTable dt = null;
strSQL = "SELECT DISTINCT [Employees].EmployeeID FROM [Employees] WHERE [Employees].Logon = 'User1'";
dt = new DataTable();
dt = Database.RunQueryAndReturnAsDataTable(strSQL);
}
请求的信息,RunQueryAndReturnAsDataTable():
protected internal static DataTable RunQueryAndReturnAsDataTable(string strSQL)
{
DataTable dt = null;
// put our query into a datatable and return it
using (SqlConnection sqlConn = new SqlConnection(Constants.DATABASE_CONNECTION_STRING))
{
using (SqlCommand sqlCmd = new SqlCommand(strSQL, sqlConn))
{
sqlConn.Open();
using (SqlDataReader sqlReader = sqlCmd.ExecuteReader())
{
if (sqlReader.HasRows)
{
dt = new DataTable();
dt.Load(sqlReader, LoadOption.OverwriteChanges);
}
}
}
}
}
当我使用代码时,代码也停止在同一行运行,产生相同的错误。
using (SqlDataReader sqlReader = sqlCmd.ExecuteReader())
有没有人遇到过这个问题?我怎样才能解决这个问题?请指教,谢谢!