【发布时间】:2018-01-19 14:48:48
【问题描述】:
这似乎是我的计算机或 azure sql 服务器的问题。我以前遇到的问题不是问题,但是代码突然表现得很奇怪。这是我用来工作的代码。连接成功打开,我的 executenonquery 工作正常,但读者行为奇怪。
public static List<ClientDto> GetClientInformation()
{
List<ClientDto> results = new List<ClientDto>();
try
{
using (var sqlConnection =
new SqlConnection(ConfigurationManager.ConnectionStrings["ClientData"].ConnectionString))
{
using (var command = new SqlCommand(null, sqlConnection))
{
sqlConnection.Open();
command.CommandType = CommandType.StoredProcedure;
//running the GetClientInformation stored procedure in DB
command.CommandText = Constants.GetClientInformation;
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
results.Add(new ClientDto()
{
Id = Convert.ToInt32(reader["Id"].ToString()),
DealerName = reader["DealerName"].ToString(),
GroupID = reader["GroupID"].ToString(),
DealerId = reader["DealerId"].ToString(),
DealerFolderName = reader["DealerFolder"].ToString(),
DMSType = reader["DMSType"].ToString(),
MAIsActive = Convert.ToBoolean(Convert.ToInt32(reader["MAIsActive"])),
SalesIsActive = Convert.ToBoolean(Convert.ToInt32(reader["SalesIsActive"])),
SalesSource = reader["SalesSource"].ToString(),
InventoryIsActive = Convert.ToBoolean(Convert.ToInt32(reader["InventoryIsActive"])),
InventorySource = reader["InventorySource"].ToString(),
AppointmentsIsActive =
Convert.ToBoolean(Convert.ToInt32(reader["AppointmentsIsActive"])),
AppointmentsSource = reader["AppointmentsSource"].ToString(),
LeadsIsActive = Convert.ToBoolean(Convert.ToInt32(reader["LeadsIsActive"])),
LeadsSource = reader["LeadsSource"].ToString(),
ServiceIsActive = Convert.ToBoolean(Convert.ToInt32(reader["ServiceIsActive"])),
ServiceSource = reader["ServiceSource"].ToString(),
SalesIsDelete = Convert.ToBoolean(Convert.ToInt32(reader["SalesIsDelete"])),
SalesDeleteRange = reader["SalesDeleteRange"].ToString(),
InventoryIsDelete = Convert.ToBoolean(Convert.ToInt32(reader["InventoryIsDelete"])),
InventoryDeleteRange = reader["InventoryDeleteRange"].ToString(),
AppointmentsIsDelete =
Convert.ToBoolean(Convert.ToInt32(reader["AppointmentsIsDelete"])),
AppointmentsDeleteRange = reader["AppointmentsDeleteRange"].ToString(),
LeadsIsDelete = Convert.ToBoolean(Convert.ToInt32(reader["LeadsIsDelete"])),
LeadsDeleteRange = reader["LeadsDeleteRange"].ToString(),
ServiceIsDelete = Convert.ToBoolean(Convert.ToInt32(reader["ServiceIsDelete"])),
ServiceDeleteRange = reader["ServiceDeleteRange"].ToString(),
IsActive = Convert.ToBoolean(Convert.ToInt32(reader["IsActive"])),
UserDefinedName = reader["UserDefinedName"].ToString()
});
}
}
}
return results;
}
catch (Exception ex)
{
//If an exception happens it will insert the error to errorlog table and to the log file
Logger.WriteError(new ErrorDto()
{
Source = "GetClientInformation",
Message = ex.Message,
StackTrace = ex.StackTrace
});
Console.WriteLine(string.Format("Error - {0} - {1} ", "GetClientInformation", ex.Message));
return results;
}
}
sql中有数据,我的应用程序的可执行文件在我们的虚拟机(Windows Server)上运行良好。 我在代码中看到的唯一奇怪的事情是 SQLConnection 有这个内部异常(虽然它并没有停止代码运行) ServerVersionNormalized = 'sqlConnection.InnerConnection.ServerVersionNormalized' 引发了“System.NotSupportedException”类型的异常 我不确定这是否是以前的问题。
This picture shows that Enamration yielded no result
This picture shows that reader has rows
我现在正在重新安装我的 Visual Studio,看看它是否能解决问题。 对我来说,这个问题在 Visual Studio 2015 和 2017 中都发生了。
这是我的连接字符串格式: 服务器=.database.windows.net,1433;数据库=;用户 ID=;密码=;Trusted_Connection=False;加密=真;
【问题讨论】:
-
检查你的 sql server 版本。不是VS。
-
据我所知,sql server 没有任何变化,它是一个 azure 服务器,它工作的时候是 2012 年,现在也是 2012 年,除非我在 Azure 中发生了变化我不知道。
-
是sql server还是azure db?
-
它是在 Azure SQL Server 上创建的 Azure DB
-
然后阅读文档,看看是否支持。我怀疑是你的存储过程调用导致了问题
标签: c# visual-studio azure sqldatareader sqlconnection