Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Importance of the parenthesis "()" <--- ???

Status
Not open for further replies.
Jul 10, 2001
5
US
The following are 2 lines that opens a sql connection via the sql .net namespace. The first line does not work, but the second line does. The only difference is the () after the Open function.

When I use the VS 2005 IDE, I believe this is optional, but apparently in PowerShell, this is not. I've done some simple programming, but I don't understand the significance of the parenthesis. Can somebody let me know or link me some info? Thanks!

DOES NOT WORK!
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection "server=myserver;database=database1;Integrated Security=sspi"
$SqlConnection.Open

WORKS!
$sqlConnection = new-object System.Data.SqlClient.SqlConnection "server=myserver;database=database1;Integrated Security=sspi"
$sqlConnection.Open()
 
I can't swear to it but I think the significance is that you are calling a function and the empty parenthesis indicate you are calling it without any arguments.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top