Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-server-2005 C#
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 2:41am
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 at 13-Feb-12 7:46am
   
what does it mean by "Your-connection-string"..???
Rajesh Anuhya at 13-Feb-12 7:46am
   
that is your connection string using for the sqlserver connection.
--RA
Dinesh92 at 13-Feb-12 7:49am
   
what are the namespace required for this...???
Dinesh92 at 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 at 13-Feb-12 7:58am
   
the above link will list all the available Sql servers.
Dinesh92 at 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
0 Sergey Alexandrovich Kryukov 380
1 OriginalGriff 230
2 DamithSL 200
3 Zoltán Zörgő 149
4 BillWoodruff 120
0 OriginalGriff 7,610
1 DamithSL 5,559
2 Sergey Alexandrovich Kryukov 5,324
3 Maciej Los 4,961
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 11 Dec 2012
Copyright © CodeProject, 1999-2014
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