Determine ActiveSync state from NETCF ?

  • Thread starter Thread starter garfitz
  • Start date Start date
G

garfitz

My app needs to replicate (SQLCE) via internet or activesync
connection.

A different URL is used depending on the type of connection available
(activesync or gprs).

Is there a way of knowing if a valid activesync connection is
available from within .NET ?
 
Check the connection to the URL

========================================================================

string InternetUrl = "";

if (CheckConnection.Once("http://100.100.100.10/cerep2/sscesa20.dll") ==
true)

InternetUrl = http://GPRS_IP/RepFolder/sscesa20.dll;

else

InternetUrl = http://ActivSync_IP/RepFolder/sscesa20.dll;

============================================================================
=====

using System;

using System.Net;

namespace Delta_Stocktaking

{

/// <summary>

/// Utility class for checking connection.

/// </summary>

public class CheckConnection

{

/// <summary>

/// Check (HTTP) connection once.

/// </summary>

/// <param name="targetAddress">Target address (URL or IP) to check</param>

/// <returns>Whether connection exist to target address</returns>

public static bool Once(string targetAddress)

{

HttpWebRequest request;

HttpWebResponse response;

bool isConnected = false;

try

{

request = (HttpWebRequest)WebRequest.Create(targetAddress);

response = (HttpWebResponse)request.GetResponse();

request.Abort();

// success?

if(response.StatusCode == HttpStatusCode.OK)

{

isConnected = true;

}

response.GetResponseStream().Close();

}

catch(WebException we)

{

string errMsg = we.Message;

isConnected = false;

}

catch(Exception ex)

{

string errMsg = ex.Message;

isConnected = false;

}

finally

{

request = null;

response = null;

}

return isConnected;

}

/// <summary>

/// Check (HTTP) connection a specified number of times.

/// </summary>

/// <param name="targetAddress">Target address (URL or IP) to check</param>

/// <param name="timesToCheck">Maximum number of times to check</param>

/// <returns>Whether connection exist to target address</returns>

public static bool Multiple(string targetAddress, int timesToCheck)

{

for (int i = 0; i < timesToCheck; i++)

if (Once(targetAddress))

return true;

return false;

}

}

}
 
Have implemented this.

However, once an activesync connection is made the result is always TRUE
until the soft-reset is done. This is regardless of activesync state.

Any ideas...
 
Back
Top