Click here to Skip to main content
15,902,786 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
hi friend I want to find sql server instances on my pc by using smo i have writen code
C#
DataTable dataTable = SmoApplication.EnumAvailableSqlServers(false);
string  constr2 = dataTable.Rows[0].ItemArray.GetValue(1).ToString();

but it does not gives any name of instance it showes that there is no datata at 0possion. I am using sql server 2008 & I also chck smo virsion 9.0 & 10.0 my os is win7 please help me.when i put name maully and try to connect to server it again gives error failed to connect to serter "instanceane" code which gives this error is like this
C#
Server server = new Server(new ServerConnection(constr2));
MessageBox.Show(server.Databases[0].Name);


please help me actully I wnat to create table on client pc throgh setup.exe file all thing should get attomaticlly thanks
Posted
Updated 28-Nov-11 14:19pm
v2
Comments
[no name] 28-Nov-11 20:19pm    
EDIT: updated pre tag

1 solution

Is the SQL Server Browser service running on your PC?
 
Share this answer
 
Comments
maheshpardeshi 1-Dec-11 3:07am    
yes it started
But i solve my problem by other way I got instance name by using registry editors
RegistryKery rk=Registry.LocalMachine.OpenSubKey(@"Softwaer\Microsoft\Microsoft Sql Server\");
string[] instances=rk.getvalue("installedInstance");\
string constring=System.Envirnment.machineneam.tosting()+"\\"+instances[0];
maheshpardeshi 1-Dec-11 3:09am    
by checking sql server browser it also soves this problem I hve done this on another pc thanks for reply.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900