|
I posted this on a different thread of yours but I figured I'd post it here as perhaps a different approach to your problem. I'm not entirely sure if this will work for you, but you can certainly give it a shot.
You could try using this:
using(Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer m = new Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer())
{
foreach (ServerInstance si in mc.ServerInstances)
{
Response.Write("ServerInstance:" + si.Name + "
");
}
}
You'll probably have to add a Reference to Microsoft.SqlServer.Smo
Best of luck
Cheers
Disgyza
Programmer Analyst
|
|
|
|
|
Though it seemed like it would work, it showed error in ServerInstance keyword. Added a bunch of assembly reference
using Microsoft.SqlServer.Management.Smo.Wmi;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Smo.RegisteredServers;
Looks like i'm pretty close, if only i could figure out how to find the sql server instance running, i'll be all set to post an article about the exercise
Swetha
|
|
|
|
|
public string RetrieveDataSource<br />
{<br />
get<br />
{<br />
try<br />
{<br />
System.Data.Sql.SqlDataSourceEnumerator en = System.Data.Sql.SqlDataSourceEnumerator.Instance;<br />
DataTable dt = en.GetDataSources();<br />
RegisteredServer[] rsvrs = Microsoft.SqlServer.Management.Smo.SqlServerRegistrations.EnumRegisteredServers();<br />
foreach (RegisteredServer rs in rsvrs)<br />
{<br />
serverName = rs.ServerInstance;<br />
}<br />
}<br />
catch (Exception ex)<br />
{<br />
ex2 = ex.Message;<br />
}<br />
return serverName;<br />
}<br />
}
The returned string is "machine name"\sqlexpress.
Atleast this returns something instead of object reference error.
Now the next question is, the Sql server instance the solution is accessing is MSSQLSERVER2008, now why would it show Sqlexpress in the output? If the answer is because its default, how to find the instance which is being currently used.
Thanks.
Swetha Sankaran
|
|
|
|
|
You should probably verify that there is only one ServerInstance being returned.
Because you are using a foreach loop and overwriting the serverName value it will always show you the last ServerInstance.
If you have more than one ServerInstance this may become a problem.
Perhaps you can store the value of the ServerInstance in the Web.config file in the AppSettings?
I'm heading home for the weekend and won't be able to check up on this post anymore until Monday. I wish you the best of luck Swetha. I'm sure you will find a solution.
Cheers
Disgyza
Programmer Analyst
|
|
|
|
|
Hi Swetha,
I got the results you were looking for.
In my case this returns more than one instance. But it does work.
Try using this
Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer mc = new Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer();
foreach (Microsoft.SqlServer.Management.Smo.Wmi.ServerInstance si in mc.ServerInstances)
{
Response.Write("ServerInstance: " + si.Name);
}
In my case it returns two instances
MSSMLBIZ
SQLEXPRESS
Cheers
Disgyza
Programmer Analyst
|
|
|
|
|
Hey cool..will try it rightaway...thanks disgyaza. You have an awesome weekend!!
Swetha
|
|
|
|
|
Stop posting and deleting
Alexei Rodriguez
|
|
|
|
|
I WILL continue to update the code and WILL delete that which is obsolete. The code that was deleted were updated and posted back based on further research and modifications.
Swetha
|
|
|
|
|
swetha sankaran wrote: The code that was deleted were updated and posted back based on further research and modifications.
It looks like you have no idea of what this forum is for
First do "research", then if you dont find the answer, then post, and let the post grow as more people enriches the post
If you continue doing that, i WILL block your account for posting
Alexei Rodriguez
|
|
|
|
|
|
Thats what dubug the application and check which object is null ..
swetha sankaran wrote: String[] instances = (String[])rk.GetValue("InstalledInstances");
Make sure that
rk is not null have if block there and check if (rk != null ) then do that
Thanks and Regards
Sandeep
If If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
Check My Blog
|
|
|
|
|
Does that key exists on your box? on mine with sql2005 it doesnt...
|
|
|
|
|
I think the right path is :
RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server");
|
|
|
|
|
Perhaps you need to create a new instance of your RegistryKey.
Try the using key word
using(RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft SQL Server"))
{
String[] instances = (String[])rk.GetValue("InstalledInstances");
}
Not entirely sure if that will work for you.
Good luck
Cheers
Disgyza
Programmer Analyst
|
|
|
|
|
|
if have problems getting machine name use:
string name=Environment.GetEnvironmentVariable("computername");
|
|
|
|
|
|
|
You could try using this:
using(Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer m = new Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer())
{
foreach (ServerInstance si in mc.ServerInstances)
{
Response.Write("ServerInstance:" + si.Name + "<br />");
}
}
You'll probably have to add a Reference to Microsoft.SqlServer.Smo
Best of luck
Cheers
Disgyza
Programmer Analyst
|
|
|
|
|
Hi All,
We are facing below issue in the application. Its happening very seldom and for specific users only.
Out of 100 users it is happening for 1 or 2 users.
In the application when we are making a service call it is throwing this excpetion.
please can any one tell me what can be reason?
I tried google there are many reasons but i am not able to conclude and reproduce the exception.
Its very intresting as its working fine for all other users but for some specific users its not working
The request failed with HTTP status 400: Bad Request. Stack: at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
Thanks and Regards
Sandeep
If If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
Check My Blog
modified on Friday, April 24, 2009 1:56 PM
|
|
|
|
|
Seems that you are using webService and for some reason the response returned to asp application is not well formed, maybe the problem could be with the webService. The problem occurs in specific pages? or random pages?
|
|
|
|
|
Thanks for the reply..
Yeah the problem occurs for a specific call in a perticular page...
This call is getting failed only for some users ....
We never got this issue in the QA. But in the production very few users are having this problem.
At our end we are not able to reproduce the issue.
The service that we are calling is third party. There they are saying that they are not getting any request ..
Request is getting failed ....
We are not sure what can be the issue to fix it
Thanks and Regards
Sandeep
If If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
Check My Blog
|
|
|
|
|
Well, the problem is with one particular page, one service, maybe one particula webMethod?
Maybe the users with problem has the same work to do, so only them use that part of the webService, that could explain why only they are being affected.
In order to reproduce the bug, you must identifi the webMethod (or methods) and send the same information than the user are sending to receive the same answer from the service.
|
|
|
|
|
Rolcr wrote: the problem is with one particular page, one service, maybe one particula webMethod?
Exactly, only for one perticual webmethod we are facing this issue and only for some users ....
Rolcr wrote: In order to reproduce the bug, you must identifi the webMethod (or methods) and send the same information than the user are sending to receive the same answer from the service.
We knew the WebMethod. and we send the same information data the users are sending and we were able to send that information ...
Thats the problem we are not able to replroduce the issue....
We know issue is there as we are seeing exceptions in the production log
Thanks and Regards
Sandeep
If If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
Check My Blog
|
|
|
|
|