Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««56789»»

Database Space Capacity Planning Expand / Collapse
Author
Message
Posted Friday, August 17, 2012 9:42 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, May 6, 2014 6:14 AM
Points: 4, Visits: 107
I changed the script to pull the server name from __Server instead of SystemName because a few of my servers had no information in that field. After doing that the column mapping gets skewed and columns from the data table are not matched up with the columns from the sql table durring the writetoserver call. Any idea's on how this column mapping can be set?
Post #1346624
Posted Friday, August 17, 2012 11:04 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, May 6, 2014 6:14 AM
Points: 4, Visits: 107
I answered my own questions. You need to use:

$bulkCopy.ColumnMappings.Add("SourceCol", "DestCol")

to define the mapping between columns.
Post #1346678
Posted Friday, August 17, 2012 12:59 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 5:13 AM
Points: 259, Visits: 713
You got it. Sometimes I'll just recreate the table definition to match the column order in order to avoid mappings.

If you go that route you'll need to look at the column order after its been converted to a datatable using get-member.



Post #1346720
Posted Wednesday, October 3, 2012 6:16 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, October 13, 2014 3:45 AM
Points: 6, Visits: 61
Hi, getting an error in the write-VolToDb

Exception calling "WriteToServer" with "1" argument(s): "Column 'server_name' does not allo
w DBNull.Value."
At C:\Bin\Write-VolToDb.ps1:89 char:28
+ $bulkCopy.WriteToServer <<<< ($dt)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException

Table is populated with one server, stepping through in debug mode (PowerGUI) is showing all parameters and connection strings are correct. Running a C:\Bin\test.ps1 connects and returns the correct server held in the server_space_iku.

Any ideas?
Post #1367607
Posted Wednesday, October 3, 2012 5:21 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 5:13 AM
Points: 259, Visits: 713
Take a look at the $dt variable and make sure server_name property has a value.


Post #1368109
Posted Thursday, October 4, 2012 1:47 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, October 13, 2014 3:45 AM
Points: 6, Visits: 61
Yeah throughout the debugging, the @dt variable never appeared to have a value assigned. All other variables were populated, including server name etc
Post #1368208
Posted Thursday, October 4, 2012 2:44 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, October 13, 2014 3:45 AM
Points: 6, Visits: 61
I have narrowed it down. Removing the Primary Key from the table vol_space and allowing NULLS on the server_name field inserts records but without a server name. Somewhere the server\computer name is not being populated, maybe in the Out-DataTable funtion. The column names picked and added to the data table are:

FreeGb
Label
Name
PercentFree
SizeGB
SystemName ?
UsageDT

SystemName appears to be the culprit?
Post #1368236
Posted Thursday, October 4, 2012 8:19 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 5:13 AM
Points: 259, Visits: 713
Not sure why SystemName would be null. Let's try forcing the systemname. Replace the existing Get-Vol function with this version:
#######################
function Get-Vol
{
param($computerName)

Get-WmiObject -computername "$ComputerName" Win32_Volume -filter "DriveType=3" |
foreach { add-member -in $_ -membertype noteproperty UsageDT $((Get-Date).ToString("yyyy-MM-dd"))
add-member -in $_ -membertype noteproperty SizeGB $([math]::round(($_.Capacity/1GB),2))
add-member -in $_ -membertype noteproperty FreeGB $([math]::round(($_.FreeSpace/1GB),2))
add-member -in $_ -membertype noteproperty PercentFree $([math]::round((([float]$_.FreeSpace/[float]$_.Capacity) * 100),2))
add-member -in $_ -MemberType noteproperty SystemName $ComputerName -force -PassThru } |
select UsageDT, SystemName, Name, Label, SizeGB, FreeGB, PercentFree

}# Get-Vol



Post #1368451
Posted Thursday, October 4, 2012 9:07 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, October 13, 2014 3:45 AM
Points: 6, Visits: 61
Yes, that has fixed it. Thank you.

I wonder why this happened.
Post #1368497
Posted Thursday, October 18, 2012 8:26 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, November 4, 2013 3:44 AM
Points: 5, Visits: 127
Hi All,

In SQL Server 2008 instance i have created spacedm database and created all objects tables,views,sp's

I've executed this command prompt .\write-dbspacetodb.ps1 'instancename' spacedm

I am getting below error from powershell. An exception calling "fill" with "1" can't open database spacedm. Login failed to open Spacedm database

Please help me how to resolve this issue. I have created one login assigned db_owner to spacedm even then same issue.


Post #1374407
« Prev Topic | Next Topic »

Add to briefcase «««56789»»

Permissions Expand / Collapse