Solved

error on cmd split when dbname contains _

Posted on 2013-05-28
4
272 Views
Last Modified: 2013-05-29
Hello,

When I try to execute the following command, an error occurs if dbname contains _ :
$LIST_DBM = (&sqlcmd -E -S $server -d master -h -1 -W -b -Q " set nocount on;SELECT DB_NAME(database_id) +'|'+ mirroring_role_desc +'|'+ mirroring_state_desc FROM sys.database_mirroring WHERE mirroring_guid IS NOT NULL;")


$DB_NAME = $LIST_DB.split("|")[0]

Method invocation failed because [System.Object[]] doesn't contain a method named 'split'.

How can I resolve this problem?

Thanks
0
Comment
Question by:bibi92
  • 2
  • 2
4 Comments
 
LVL 39

Expert Comment

by:footech
ID: 39201963
I don't think that the value of $DB_NAME containing a underscore is the problem.  What the error is saying is that $DB_NAME is an array, not a string, and thus the split method doesn't exist for an array.  If it is an array of strings, you could apply a foreach loop to use the split method on each element of the array.
0
 

Author Comment

by:bibi92
ID: 39202043
Hello,

I try this :

  foreach ( $dbmirr in $LIST_DBM ) {
      $array_str = $LIST_DBM[$dbmirr].split("|")
      $DB_NAME = $array_str[0]
      $MIRR_ROLE_DESC = $array_str[1]
      $MIRR_STATE_DESC = $array_str[2
}
The following error is returned :
You cannot call a method on a null-valued expression.
$array_str = $LIST_DBM[$dbmirr].split("|")

Thanks
0
 
LVL 39

Accepted Solution

by:
footech earned 500 total points
ID: 39202112
How about this?
foreach ( $dbmirr in $LIST_DBM ) {
      $array_str = $dbmirr.split("|")
      $DB_NAME = $array_str[0]
      $MIRR_ROLE_DESC = $array_str[1]
      $MIRR_STATE_DESC = $array_str[2
}

Open in new window

0
 

Author Closing Comment

by:bibi92
ID: 39203772
Thanks
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Utilizing an array to gracefully append to a list of EmailAddresses
Synchronize a new Active Directory domain with an existing Office 365 tenant
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now