I have following database statement: (and files, access and everything is ready for executing this statement)
CREATE DATABASE [test1] ON
(FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\test1.mdf'),
(FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\test1_log.ldf')
FOR ATTACH
And when I do it via c#
it returns me more than one value.
public void RunQuery(string query, bool longRunning = false)
{
using (var cmd = new SqlCommand(query, Connection))
{
cmd.CommandTimeout = longRunning ? _longRunningCommandTimeout : _commandTimeout;
cmd.ExecuteNonQuery();
}
}
Error: Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
The statement has been terminated
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()
The database is actually attached despite of returning this error.
And it's really weird. Because usually it's just a message.
And moreover when I execute the same query(under the same user) via MSSMS
it gets me just the following:
Commands completed successfully.
Is it possible that create database
statement returns more than one result ?