SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Database Space Capacity Planning


Database Space Capacity Planning

Author
Message
klecknerl
klecknerl
Forum Newbie
Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)

Group: General Forum Members
Points: 8 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?
klecknerl
klecknerl
Forum Newbie
Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)

Group: General Forum Members
Points: 8 Visits: 107
I answered my own questions. You need to use:

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

to define the mapping between columns.
cmille19
cmille19
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1285 Visits: 726
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.



slk55guy
slk55guy
Valued Member
Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)

Group: General Forum Members
Points: 50 Visits: 89
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: (Smile [], 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?
cmille19
cmille19
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1285 Visits: 726
Take a look at the $dt variable and make sure server_name property has a value.



slk55guy
slk55guy
Valued Member
Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)

Group: General Forum Members
Points: 50 Visits: 89
Yeah throughout the debugging, the @dt variable never appeared to have a value assigned. All other variables were populated, including server name etc
slk55guy
slk55guy
Valued Member
Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)

Group: General Forum Members
Points: 50 Visits: 89
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?
cmille19
cmille19
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1285 Visits: 726
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




slk55guy
slk55guy
Valued Member
Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)

Group: General Forum Members
Points: 50 Visits: 89
Yes, that has fixed it. Thank you. :-)

I wonder why this happened.
narayanaswamy
narayanaswamy
Grasshopper
Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)

Group: General Forum Members
Points: 17 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.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search