Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-server-2005C#
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
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
Your Filters
Interested
Ignored
     
0 Shai Vashdi 576
1 OriginalGriff 183
2 Tadit Dash 170
3 Sergey Alexandrovich Kryukov 156
4 Peter Leow 130
0 Sergey Alexandrovich Kryukov 9,325
1 OriginalGriff 5,473
2 Peter Leow 4,150
3 Maciej Los 3,540
4 Abhinav S 3,333


Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 11 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid