Hello everyone. I have a project that was built using SQL Server 2001 and I recently upgraded to SQL Server 2017. I realize that is a big jump.
After the upgrade, I have noticed some strange SQL errors and haven't been able to figure out where the issue lies. I haven't found anything online that would indicate that SQL itself has changed from what I was writing previously, and the threads
I've read where people were discussing these issues don't seem to discuss causes that would apply here...
For starters, here is the first error I'm getting:
Exception: System.Data.SqlClient.SqlException (0x80131904): Invalid column name 'Name'.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite,
Boolean inRetry)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
at PD1.UContactList.GridBW_DoWork(Object sender, DoWorkEventArgs e)
ClientConnectionId:537a9e7e-6f69-4c8e-bbd4-b0138540dc27
Error Number:207,State:1,Class:16
And here is my SQL:
SELECT Leads.ID, Leads.LeadType, Leads.LeadType AS [SalesType], Leads.Company, Leads.FName, Leads.LName, COALESCE(NULLIF(Leads.Company,
'') + ' - ', '') + COALESCE(Leads.FName, '') + ' ' + COALESCE(Leads.LName, '') AS[Name], Leads.WPhone, Leads.MPhone, Leads.OPhone, Leads.OPhoneNote, Leads.Fax, Leads.Address1, Leads.Address2, Leads.City, Leads.State, Leads.Zip, Leads.EMail,
Leads.Website, Leads.Notes, Leads.WritesFor, Leads.OfficeStaff, Leads.SalesRoute, Leads.SalesStop, Leads.SalesRating, Leads.MarketCategory, Leads.SalesActivity, Leads.DateCreated, Leads.CreatedBy, Leads.ChangeLog, StaffCreator.FName + ' ' + StaffCreator.LName
AS[CreatorName] FROM Leads LEFT OUTER JOIN Staff AS StaffCreator ON StaffCreator.ID = Leads.CreatedBy WHERE Leads.Company like '%searchterm%' OR Leads.FName like '%searchterm%' OR Leads.LName like '%searchterm%' OR Leads.FName + ' ' + Leads.LName like '%searchterm%' OR Leads.LName + ', ' + Leads.FName like '%searchterm, %' OR Leads.Address1
like '%searchterm%' OR Leads.Address2 like '%searchterm%' OR Leads.City like '%searchterm%' OR Leads.Zip like '%searchterm%' OR Leads.WPhone = 'searchterm' OR Leads.MPhone = 'searchterm' OR Leads.OPhone = 'searchterm' OR Leads.Fax = 'searchterm' OR Leads.EMail
= 'searchterm' OR Leads.LeadType = 'searchterm' OR Leads.WritesFor like '%searchterm%' GROUP BY Leads.ID, Leads.LeadType, Leads.Company, Leads.FName, Leads.LName, Leads.WPhone, Leads.MPhone, Leads.OPhone, Leads.OPhoneNote, Leads.Fax, Leads.EMail, Leads.Address1,
Leads.Address2, Leads.City, Leads.State, Leads.Zip, Leads.EMail, Leads.Website, Leads.Notes, Leads.WritesFor, Leads.OfficeStaff, Leads.SalesRoute, Leads.SalesStop, Leads.SalesRating, Leads.MarketCategory, Leads.SalesActivity, Leads.DateCreated, Leads.CreatedBy,
Leads.ChangeLog, StaffCreator.FName, StaffCreator.LName ORDER BY Leads.Name Desc
As you can see, the Name column does exist...
The second error I'm getting is:
Exception: System.Data.SqlClient.SqlException (0x80131904): The multi-part identifier "Schedule.StartTime" could not be bound.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
at PD1.FMain_Customers_Schedule.LoadConflictingAppointments()
ClientConnectionId:5c7d09c5-7c17-40d7-93ae-437a2ad61465
Error Number:4104,State:1,Class:16
And the SQL is:
SELECT TOP 1 Schedule.ID AS SID, Schedule.Subject, Schedule.StartTime, Schedule.EndTime FROM Schedule WHERE Schedule.LaborID = '8' AND ('8/15/2018 12:05:01 PM' BETWEEN Schedule.StartTime AND Schedule.EndTime OR '8/15/2018 12:55:00 PM' BETWEEN Schedule.StartTime AND Schedule.EndTime) ORDER BY Schedule.StartTime Asc
So, you can see that Schedule.StartTime is there...?
Does anyone happen to know what might be causing these issues? They seem to be connected, but I'm not sure. Discussion online centered around these fields not being there, but I can assure you that they are and this SQL has worked for quite some time which wouldn't have happened if they weren't there. Is there a symantec change that I am unaware of perhaps?
Other SQL scripts are working, but not all...
Thank you again for your help!