c# - Can't change sql server file database size -
this question has reply here:
how utilize variable database name in t-sql? 4 answersi can't alter database file size c# query. reason exception: "incorrect syntax near '@databasename'.
this code executed query:
command = connection.createcommand(); command.commandtext = @" alter database @databasename modify file (name = @databasefile, size = @newsize) "; dbparam = command.createparameter(); dbparam.parametername = "databasefile"; dbparam.value = dbfilename; command.parameters.add(dbparam); dbparam = command.createparameter(); dbparam.parametername = "newsize"; dbparam.value = newsize; command.parameters.add(dbparam); dbparam = command.createparameter(); dbparam.parametername = "databasename"; dbparam.value = databasename; command.parameters.add(dbparam); command.executenonquery();
now there might several problems. firstly database on different machine wouldn't db file path different?
some things cannot parameterized. includes things table , column names in dml, includes most of ddl. not expecting, , cannot process, parameters in scenario.
to check this; run in ssms, declaring variables ahead of time , giving them values. find error message same. if doesn't work in ssms unlikely work ado.net.
c# sql-server
No comments:
Post a Comment