我已经看过从Azure Power
shell运行sql命令的示例,例如
$connectionString = "Data Source=MyDataSource;Initial Catalog=MyDB;User ID=user1;Password=pass1;Connection Timeout=90" $connection = New-Object -TypeName System.Data.sqlClient.sqlConnection($connectionString) $query = "CREATE TABLE...." $command = New-Object -TypeName System.Data.sqlClient.sqlCommand($query,$connection) $connection.Open() $command.ExecuteNonQuery() $connection.Close()
有没有办法用引用包含整个sql脚本的外部文件替换$query?
谢谢.
解决方法
再搜索20分钟,我发现了它.
$connectionString = "Data Source=MyDataSource;Initial Catalog=MyDB;User ID=user1;Password=pass1;Connection Timeout=90" $connection = New-Object -TypeName System.Data.sqlClient.sqlConnection($connectionString) $query = [IO.File]::ReadAllText("C:\...\Testsql.sql") $command = New-Object -TypeName System.Data.sqlClient.sqlCommand($query,$connection) $connection.Open() $command.ExecuteNonQuery() $connection.Close()