I am using the Copy Database feature in SSMS. The source instance is v 2012, the target instance is v 2019.
I am able to copy other databases in the source instance to the target instance. This particular database fails.
This message is from the Windows Event Viewer on the target machine. "InnerException-->Invalid column name 'Description'." does not make sense because there is
a column with that name in one of the tables in the source database. I can't tell what table it's complaining about from the message in the Windows Event Log.
There is one table in the source database with a column called Description:
Event Name: OnError
Message: An error occurred while transferring data. See the inner exception for details.
StackTrace: at Microsoft.SqlServer.Management.Smo.Transfer.TransferData()
at Microsoft.SqlServer.Dts.Tasks.TransferObjectsTask.TransferObjectsTask.TransferDatabasesUsingSMOTransfer()
InnerException-->Invalid column name 'Description'.
StackTrace: 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.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at Microsoft.SqlServer.Management.Smo.Transfer.ExecuteStatements(SqlConnection destinationConnection, IEnumerable`1 statements, SqlTransaction transaction)
at Microsoft.SqlServer.Management.Smo.Transfer.TransferData()
Operator: NT Service\SQLAgent$MSSQLSERVER2019
Source Name: CDW_IL-SERVER-001_MSSQLSERVER2012_IL-SERVER-002_MSSQLSERVER2019_8
Source ID: {6FCAF562-8C02-4A7F-BDE0-9B985BE99BCB}
Execution ID: {C9D1672E-366F-49C2-B98F-903B080DF36A}
Start Time: 8/14/2020 9:11:21 AM
End Time: 8/14/2020 9:11:21 AM
Data Code: 0
Related
'''
Try
Dim connectionString As String = "Server=" & SERVER_NAME & ";Database=" & DB_NAME & ";User Id=" & USER_ID & ";Password=" & PASSWORD_STRING
Using conn As New SqlConnection(connectionString)
conn.Open()
Using adapter As New SqlDataAdapter("SELECT * FROM CUSTOM_VIEW", conn)
adapter.Fill(dtCustom_view)
End Using
End Using
Catch ex As Exception
Console.WriteLine(ex)
Console.WriteLine("Press any key...")
Console.ReadKey()
Environment.Exit(0)
End Try
'''
Problem is when connection is made to DB_NAME="One" works fine, when DB_NAME="Two" exeption is rised
Both schemas are on the same server. I can connect to both schemas using ODBC with same username and password. Problem rised after user have upgraded SQL server to compatibility level 2019. Prior it was 2008 and there were no problem to connect to both schemas.
System.Data.SqlClient.SqlException (0x80131904): Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 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.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
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(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
at iSAF.Module1.Main(String[] args)
ClientConnectionId:ba3bf0f6-683d-4394-9d4d-43948269e5da
Error Number:-2,State:0,Class:11
Problem rised after user have upgraded SQL server to compatibility level 2019. Prior it was 2008 and there were no problem to connect to both schemas.
You should turn on Query Store to gather query performance baselines before increasing the compatibility level.
Our .net core Web API is hosted in Azure App service and is connecting to on-premises MS SQL server 2008 using a policy based VPN connection, we are sporadically getting this error.I'm sure this is a network-related error and not a query related error as the query is a simple select statement against a table with 10 rows.
System.Data.SqlClient.SqlException (0x80131904): A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - The semaphore timeout period has expired.)
---> System.ComponentModel.Win32Exception (121): The semaphore timeout period has expired.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParserStateObject.ThrowExceptionAndWarning(Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error)
at System.Data.SqlClient.TdsParserStateObject.ReadSniSyncOverAsync()
at System.Data.SqlClient.TdsParserStateObject.TryReadNetworkPacket()
at System.Data.SqlClient.TdsParserStateObject.TryPrepareBuffer()
at System.Data.SqlClient.TdsParserStateObject.TryReadByte(Byte& value)
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)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues)
ClientConnectionId:f904e92c-2b13-4d2a-9868-c5bc14005fb9
Error Number:121,State:0,Class:20
Some of my queries having Left joins and Unions were working perfectly till the data in my base tables crossed couple of thousand records.
Now the same queries in the stored procedures are raising timeout errors.
I am not sure whether to tweak the SQL queries from my side or do any memory settings on SQL server.
Error Text:
A timeout occurred while waiting for memory resources to execute the
query in resource pool 'internal' (1). Rerun the query.
8/28/2018 7:15:50 AM Error: A timeout occurred while waiting for
memory resources to execute the query in resource pool 'internal' (1).
Rerun the query. at
System.Data.SqlClient.SqlConnection.OnError(SqlException exception,
Boolean breakConnection, Action1 wrapCloseInAction) at
System.Data.SqlClient.SqlInternalConnection.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.TryHasMoreRows(Boolean& moreRows)
at System.Data.SqlClient.SqlDataReader.TryReadInternal(Boolean
setTimeout, Boolean& more) at
System.Data.SqlClient.SqlDataReader.Read() at
XXXXXX.Dal.Configuration.ConfigurationDAL.GetUsers(String
tenantConnectionString, Int32 entityId, Boolean includeUserGroups,
Int32 getUsersMode)
I am building out my database using EF Core 2.1 code first migrations. I have altered a table to rename. The migration initially dropped the entire table and then read it with the new name, which had issues with foreign key constraints. I changed the migration to use the RenameTable method instead like
migrationBuilder.RenameTable("TourSpecs", "TourSpecHistory");
When running update-database I get the error
Failed executing DbCommand (27ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
DECLARE #defaultSchema sysname = SCHEMA_NAME();
EXEC(N'ALTER SCHEMA ' + #defaultSchema + N' TRANSFER [TourSpecHistory].[TourSpecs];');
fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
Failed executing DbCommand (27ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
DECLARE #defaultSchema sysname = SCHEMA_NAME();
EXEC(N'ALTER SCHEMA ' + #defaultSchema + N' TRANSFER [TourSpecHistory].[TourSpecs];');
System.Data.SqlClient.SqlException (0x80131904): Cannot find the object 'TourSpecs', because it does not exist or you do not have permission.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 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.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource1 completion, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite, String methodName)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues)
ClientConnectionId:332393e8-8539-4c80-b24c-6478ec61b55b
Error Number:15151,State:1,Class:16
System.Data.SqlClient.SqlException (0x80131904): Cannot find the object 'TourSpecs', because it does not exist or you do not have permission.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 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.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource1 completion, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite, String methodName)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary2 parameterValues)
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary2 parameterValues)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.ExecuteNonQuery(IEnumerable`1 migrationCommands, IRelationalConnection connection)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
ClientConnectionId:332393e8-8539-4c80-b24c-6478ec61b55b
Error Number:15151,State:1,Class:16
Cannot find the object 'TourSpecs', because it does not exist or you do not have permission.
Thinking this is just a permissions issue I ran the command
GRANT ALTER ON SCHEMA:: [dbo].[TourSpec] TO ApplicationLogin
But was hit with the error
Cannot find the schema 'dbo.TourSpec', because it does not exist or you do not have permission.
The login I am using to run the grant script has the ALTER ANY SCHEMA permission. What do I need to do to get the correct permissions granted to my ApplicationLogin user?
After #Sean Lange pointed out that I had an incorrect understanding of what was a schema and what an object, I successfully granted the permissions to my user but was still unable to run the migration. Looking through the RenameTable method further, I discovered that it takes in 3 optional arguments at the end and that the migration was incorrectly try to alter a [TourSpecHistory].[TourSpecs] table.
I changed the migration to run migrationBuilder.RenameTable("TourSpecs", "dbo", "TourSpecHistory", "dbo"); and it now works correctly
I've got problem with renaming column and migrating changes to database.
Migration:
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "int",
schema: "Gamgoo.More",
table: "Rating",
newName: "GivenRating");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "GivenRating",
schema: "Gamgoo.More",
table: "Rating",
newName: "int");
}
Commands that I'm using are (from Package Manager Console / Powershell):
Add-Migration RatingFix -p Gamgoo.Data.Context -c GamgooContext
Update-Database
And the error message:
Applying migration '20180319172151_RatingFix'.
Microsoft.EntityFrameworkCore.Migrations[200402]
Applying migration '20180319172151_RatingFix'.
fail: Microsoft.EntityFrameworkCore.Database.Command[200102]
Failed executing DbCommand (31ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
EXEC sp_rename N'Gamgoo.More.Rating.int', N'GivenRating', N'COLUMN';
System.Data.SqlClient.SqlException (0x80131904): Either the parameter #objname is ambiguous or the claimed #objtype (COLUMN) is wrong.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.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.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite, String methodName)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues)
ClientConnectionId:ba25aa03-122d-4c55-9673-4bd3358f2f83
Error Number:15248,State:1,Class:11
Failed executing DbCommand (31ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
EXEC sp_rename N'Gamgoo.More.Rating.int', N'GivenRating', N'COLUMN';
System.Data.SqlClient.SqlException (0x80131904): Either the parameter #objname is ambiguous or the claimed #objtype (COLUMN) is wrong.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.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.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite, String methodName)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues)
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
at Microsoft.EntityFrameworkCore.Migrations.MigrationCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.ExecuteNonQuery(IEnumerable`1 migrationCommands, IRelationalConnection connection)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_1.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
ClientConnectionId:ba25aa03-122d-4c55-9673-4bd3358f2f83
Error Number:15248,State:1,Class:11
Either the parameter #objname is ambiguous or the claimed #objtype (COLUMN) is wrong.
I've checked ef core github, forum and stackoverflow for similar problems, but those answers did not helped me.
I would like to avoid removing all migrations and updating the database, because I already have quite a lot of data in other tables.
This may have been fixed by PR #11161. You can try the nightly builds.
You can work around the issue by rewriting the sp_rename call:
// UNDONE: SQL generated by EF Core is missing schema identifier quotes
//migrationBuilder.RenameColumn(
// name: "int",
// schema: "Gamgoo.More",
// table: "Rating",
// newName: "GivenRating");
migrationBuilder.Sql(
"EXEC sp_rename N'[Gamgoo.More].[Rating].[int]', N'GivenRating', N'COLUMN';");
I got this same issue while trying to rename a column that I had added to the identity User. After checking the database, I realized that I had created the migration to generate the original column, but never actually updated the database. Earlier in some frustration I had deleted the migration that would have generated the column had I actually updated the database. Fairly easy fix - manually created the original column and then the current migration with the rename worked as expected.
Hopefully my answer may help someone else.