R
Rene Sørensen
I'm using .NET 2.0 VS 2005
I'm creating a function that dos something similar to the.
SmoApplication.EnumAvailableSqlServers() function. But for som resone
I get an error or do i?. The problem is that the program just return
from the function when it reach the recive part( reviced =
socket.Receive(bytBuffer); ), below here you can se the code. I used
eathereal to check the package that is send and reviced, that looks
all fine. I do revice the correct package from the SQLServer. Dos
anyone have a clue here? im lost after 3 days hard work on it.
Thanks is advanced
Rene
// RECIVED STRING FROM SQL SERVER
ServerName;MASTER;InstanceName;BKUPEXEC;IsClustered;No;Version;8.00.194;tcp;2369;npMASTER\pipe\M$BKUPEXEC\sql\query;;ServerName;MASTER;InstanceName;SQLEXPRE;Islustered;No;Version;9.00.2047.00;;
ArrayList servers = new ArrayList();
ArrayList list = null;
SqlServerInfo info = new SqlServerInfo();
Socket socket = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp);
socket.EnableBroadcast = true;
socket.ReceiveTimeout = 3000;
try
{
// ask for all MSSQL servers
byte[] msg = new byte[] { 0x02 };
byte[] bytBuffer = new byte[1024];
int reviced = 0;
IPEndPoint endP = new IPEndPoint(IPAddress.Broadcast, 1434);
socket.SendTo(msg, endP);
do
{
// IT JUST STOPS HERE AND RETURN FROM THE FUNCTION WITH AN
// EMPTY LIST SOMETIMES IT THROWS AN EXCEPTION
// broadcast A connection attempt failed because the connected
// party did not properly respond after a period of time, or
// established connection failed because connected host has
// failed to respond socket recive
reviced = socket.Receive(bytBuffer);
// There can be more than one instance on the same server
list = info.ParseServers(bytBuffer);
for (int i = 0; i < list.Count; i++)
{
servers.Add(new SqlServerInfo(null, (string)list));
}
socket.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.ReceiveTimeout, 300);
} while (reviced != 0);
}
catch (SocketException socex)
{
const int WSAETIMEDOUT = 10060;// Connection timed out.
const int WSAEHOSTUNREACH = 10065; // No route to host.
// Re-throw if it's not a timeout.
if (socex.ErrorCode == WSAETIMEDOUT || socex.ErrorCode ==
WSAEHOSTUNREACH)
{
// Just go away
}
else
{
throw;
}
}
finally
{
socket.Close();
}
// Copy from the untyped but expandable ArrayList, to a
// type-safe but fixed array of SqlServerInfos.
SqlServerInfo[] aServers = new SqlServerInfo[servers.Count];
servers.CopyTo(aServers);
return aServers;
I'm creating a function that dos something similar to the.
SmoApplication.EnumAvailableSqlServers() function. But for som resone
I get an error or do i?. The problem is that the program just return
from the function when it reach the recive part( reviced =
socket.Receive(bytBuffer); ), below here you can se the code. I used
eathereal to check the package that is send and reviced, that looks
all fine. I do revice the correct package from the SQLServer. Dos
anyone have a clue here? im lost after 3 days hard work on it.
Thanks is advanced
Rene
// RECIVED STRING FROM SQL SERVER
ServerName;MASTER;InstanceName;BKUPEXEC;IsClustered;No;Version;8.00.194;tcp;2369;npMASTER\pipe\M$BKUPEXEC\sql\query;;ServerName;MASTER;InstanceName;SQLEXPRE;Islustered;No;Version;9.00.2047.00;;
ArrayList servers = new ArrayList();
ArrayList list = null;
SqlServerInfo info = new SqlServerInfo();
Socket socket = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp);
socket.EnableBroadcast = true;
socket.ReceiveTimeout = 3000;
try
{
// ask for all MSSQL servers
byte[] msg = new byte[] { 0x02 };
byte[] bytBuffer = new byte[1024];
int reviced = 0;
IPEndPoint endP = new IPEndPoint(IPAddress.Broadcast, 1434);
socket.SendTo(msg, endP);
do
{
// IT JUST STOPS HERE AND RETURN FROM THE FUNCTION WITH AN
// EMPTY LIST SOMETIMES IT THROWS AN EXCEPTION
// broadcast A connection attempt failed because the connected
// party did not properly respond after a period of time, or
// established connection failed because connected host has
// failed to respond socket recive
reviced = socket.Receive(bytBuffer);
// There can be more than one instance on the same server
list = info.ParseServers(bytBuffer);
for (int i = 0; i < list.Count; i++)
{
servers.Add(new SqlServerInfo(null, (string)list));
}
socket.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.ReceiveTimeout, 300);
} while (reviced != 0);
}
catch (SocketException socex)
{
const int WSAETIMEDOUT = 10060;// Connection timed out.
const int WSAEHOSTUNREACH = 10065; // No route to host.
// Re-throw if it's not a timeout.
if (socex.ErrorCode == WSAETIMEDOUT || socex.ErrorCode ==
WSAEHOSTUNREACH)
{
// Just go away
}
else
{
throw;
}
}
finally
{
socket.Close();
}
// Copy from the untyped but expandable ArrayList, to a
// type-safe but fixed array of SqlServerInfos.
SqlServerInfo[] aServers = new SqlServerInfo[servers.Count];
servers.CopyTo(aServers);
return aServers;