Click here to Skip to main content
12,502,578 members (57,674 online)
Rate this:
 
Please Sign up or sign in to vote.
hello members,
how to get server name dynamically when my application gets installed on a machine..
i m using ADO.NET and Sql server 2005...???
Posted 13-Feb-12 1:41am
Dinesh921.4K
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

try this, this may helps you

using(SqlConnection _con = new SqlConnection(your-connection-string))
{
   string instanceName = new Microsoft.SqlServer.Management.Smo.Server
                            (new ServerConnection(_con)).InstanceName;
}


Thanks
--RA
  Permalink  
Comments
Dinesh92 13-Feb-12 7:46am
   
what does it mean by "Your-connection-string"..???
Rajesh Anuhya 13-Feb-12 7:46am
   
that is your connection string using for the sqlserver connection.
--RA
Dinesh92 13-Feb-12 7:49am
   
what are the namespace required for this...???
Dinesh92 13-Feb-12 7:54am
   
i m getting this error....


Error 1 The type or namespace name 'Management' does not exist in the namespace 'Microsoft.SqlServer' (are you missing an assembly reference?) C:\Documents and Settings\Dinesh Suthar\Desktop\WindowsApplication1\WindowsApplication1\Form1.cs 24 50 WindowsApplication1
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Comments
Michael dg 13-Feb-12 7:58am
   
the above link will list all the available Sql servers.
Dinesh92 13-Feb-12 8:02am
   
i m getting this error....


Error 1 The type or namespace name 'Management' does not exist in the namespace 'Microsoft.SqlServer' (are you missing an assembly reference?) C:\Documents and Settings\Dinesh Suthar\Desktop\WindowsApplication1\WindowsApplication1\Form1.cs 24 50 WindowsApplication1

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160919.1 | Last Updated 11 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100