Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 get instance name

Author  Topic 

mahdi87_gh
Yak Posting Veteran

72 Posts

Posted - 2009-01-06 : 09:15:34
hi,i want to create a sqlconnection string dynamic.
i work with sql2005 developer edition And C#2005.
to make a connection string i need to mashin name and sql instance name.
mashin name can obtian by this code:string name=Environment.MashinName;
but i dont know how can i get the instance name.
please help.
thanks.

****<< I Love MTN.SH >>****

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2009-01-06 : 12:24:27
Unless you have multiple named instances of SQL server installed, you don't need to specify the instance name - the default instance will be picked up. Assuming you have multiple instances, to retrieve a list of available instances, you can use SMO. SmoApplication in Microsoft.SqlServer.Management.Smo namespace has a method to enumerate the server instances.
Go to Top of Page

mahdi87_gh
Yak Posting Veteran

72 Posts

Posted - 2009-01-07 : 04:03:38
thanks a lot.
i try to add this namespace but only this "Microsoft.SqlServer.Server;" cab be added.the namespace "Microsoft.SqlServer.Management.Smo" not exist.

****<< I Love MTN.SH >>****
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2009-01-07 : 08:27:40
Add Microsoft.SqlServer.Smo in your project references. (In the solution explorer window right click on References in Solution-YourProjectName to do this).
Go to Top of Page
   

- Advertisement -