Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fc9a236

Browse files
committed
Increases Character Count in powershell script
1 parent 7d71339 commit fc9a236

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

‎Powershell/CopyDatabase.ps1

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,23 @@ $fileName = "..\Schema.sql" #Path to the Schema.sql file included in this repo
88
$tempPath = "..\BCP\" #A temp directory on a drive with enough free space to save the bcp files during the export and import operations
99
$logPath = "C:\Script_Utility\log\"
1010

11-
#Run the Schema.sql file againist the source database to get the metadata for the import
12-
$DS = Invoke-Sqlcmd -ServerInstance $ServerName -User $UserName -Password $Password -Database $SourceDatabase -InputFile $fileName -As DataSet
11+
#Get Schema Data from the database
12+
$DS = Invoke-Sqlcmd -MaxCharLength 150000-ServerInstance $ServerName -User $UserName -Password $Password -Database $SourceDatabase -InputFile $fileName -As DataSet
1313

1414
#For each row
1515
foreach($sql in $DS.Tables[0].Rows){
1616
Write-Output $sql.TableName
1717

1818
#Execute file on each database
19-
Invoke-Sqlcmd -ServerInstance $DestinationServer -Database $DestinationDB -MaxCharLength 8000 -Query $sql.SqlStatement
19+
Invoke-Sqlcmd -ServerInstance $DestinationServer -Database $DestinationDB -Query $sql.SqlStatement -OutputSqlErrors $true -verbose
20+
21+
if ($error.count -gt 0)
22+
{
23+
$error | Out-File -FilePath "$($logPath)$($sql.TableName) _sqlout.txt"
24+
$sql.SqlStatement | Out-File -FilePath "$($logPath)$($sql.TableName) _sqlout.txt"
25+
26+
$error.Clear()
27+
}
2028
Write-Output $sql.SqlStatement
2129

2230
#If we just created the table, let's import the data before applying an constraints or indexes
@@ -32,7 +40,7 @@ foreach($sql in $DS.Tables[0].Rows){
3240
Write-Output $bcp
3341

3442
#add code to import in to use format file
35-
$bcp = "bcp $($sql.SchemaName).$($sql.TableName) in $($tempPath)$($sql.TableName).bcp -S $($DestinationServer) -d $($DestinationDB) -T -t -E -f $($tempPath)$($sql.TableName).fmt -e $($logPath)$($sql.TableName)_in_err.txt"
43+
$bcp = "bcp $($sql.SchemaName).$($sql.TableName) in $($tempPath)$($sql.TableName).bcp -b 100 -S $($DestinationServer) -d $($DestinationDB) -T -t -E -f $($tempPath)$($sql.TableName).fmt -e $($logPath)$($sql.TableName)_in_err.txt"
3644
Invoke-Expression $bcp
3745
Write-Output $bcp
3846

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /