Re: Help!! Client side database access



thanks chris for reply. Yes, I like to create a remote access service (VPN)
programatically. This code below still does not able to connect. How can I
solved this? I need help. Adavnced thanks.

This inside main class
[code]
public void Dial()
{
if(_Handle!=IntPtr.Zero)
{
RASCONNSTATUS status=new RASCONNSTATUS();
uint res=RasAPI.RasGetConnectStatus(_Handle,status);

if(res==ERROR_INVALID_HANDLE) //res=ERROR_INVALID_HANDLE
_Handle=IntPtr.Zero;
else
return;
}
try
{
this._Params.szPhoneNumber = "<server ip>";
this._Params.szUserName = "<username>";
this._Params.szPassword = "dennispt200508";

RasAPI.RasCheck(RasAPI.RasDial(null,_Phonebook,_Params,1,_DialNotifyDelegate,ref _Handle));

RasAPI.RasConnectionNotification(_Handle,this._DisconnEvent.Handle,RASNOTIFICATION.RASCN_Disconnection);

RasAPI.RasDial(null,@"C:\Documents and Settings\All
Users\Application
Data\Microsoft\Network\Connections\Pbk\rasphone.pbk",_Params,1,_DialNotifyDelegate,ref _Handle);

StartWatch();

if (ConnectionState.IsModemConnected())
this.statusSend("Connected to 203.201.133.64");
else
this.statusSend("Unable to connect.");
}
catch(Exception e)
{

}
}


private void StartWatch()
{
StopWatch();
this._WatchThread=new Thread(new ThreadStart(RunWatch));
this._WatchThread.Start();
}

private void StopWatch()
{
if(this._WatchThread==null)
return;
if(this._WatchThread.IsAlive)
{
this._StopEvent.Set();
this._WatchThread.Join();
}
this._WatchThread=null;
}

private void RunWatch()
{
WaitHandle[] handles=new
WaitHandle[]{this._StopEvent,this._DisconnEvent};
int ret;
this._StopEvent.Reset();
this._DisconnEvent.Reset();
while(true)
{
ret=WaitHandle.WaitAny(handles);
if(ret==0)
break;
if(ret==1)
{
this.OnDisconnected();
System.Diagnostics.Debug.WriteLine("Dis connected");
break;
}
}
}

private void OnConnected()
{
if(this.Connected==null)
return;
EventArgs args=new EventArgs();
if(this.SynchronizingObject!=null &&
this.SynchronizingObject.InvokeRequired)
{
this.SynchronizingObject.Invoke(Connected,new object[]{this,args});
}
else
{
Connected(this,args);
}
}

private void OnDisconnected()
{
if(this.Disconnected==null)
return;
EventArgs args=new EventArgs();
if(this.SynchronizingObject!=null &&
this.SynchronizingObject.InvokeRequired)
{
this.SynchronizingObject.Invoke(Disconnected,new object[]{this,args});
}
else
{
Disconnected(this,args);
}
}

private void OnDialNotify1(IntPtr hrasconn,uint unMsg,RASCONNSTATE
rascs,uint dwError,uint dwExtendedError)
{
if(this.DialNotify1==null)
return;
string msg="";
if(dwError>0)
{
// msg=RasException.Code2RasErrorMessage(dwError);
}
else
{
// msg=RasConnection.GetRasConnStateMessage(rascs);
msg = this.GetRasConnStateMessage(rascs);
}
RasDialNotify1EventArgs args=new
RasDialNotify1EventArgs(hrasconn,unMsg,rascs,dwError,dwExtendedError,msg);

if(this.SynchronizingObject!=null &&
this.SynchronizingObject.InvokeRequired)
{
this.SynchronizingObject.Invoke(DialNotify1,new object[]{this,args});
}
else
{
DialNotify1(this,args);
}
if(args.ConnectionState==RASCONNSTATE.RASCS_Connected)
OnConnected();
}

private string GetRasConnStateMessage(RASCONNSTATE state)
{
string ret="";
if(_Res!=null)
ret=(string)_Res.GetObject(state.ToString().Trim());
return ret;
}

[Browsable(false),Description("get or set SynchronizingObject")]
public ISynchronizeInvoke SynchronizingObject
{
get
{
if(_SynchronizingObject==null)
{
if(this.DesignMode)
{
IDesignerHost dh=this.GetService(typeof(IDesignerHost)) as
IDesignerHost;
if(dh!=null)
{
_SynchronizingObject=dh.RootComponent as ISynchronizeInvoke;
}
}
}
return _SynchronizingObject;
}
set
{
_SynchronizingObject=value;
}
}
[/code]

Inside another class
[code]
internal sealed class RasAPI
{
private RasAPI(){}

[DllImport("rasapi32.dll",CharSet=CharSet.Auto)]
public extern static uint RasDial(
[In]RASDIALEXTENSIONS lpRasDialExtensions,
// pointer to function extensions data
[In]string lpszPhonebook, // pointer to full path and file
// name of phone-book file
[In]RASDIALPARAMS lpRasDialParams,
// pointer to calling parameters data
uint dwNotifierType, // specifies type of RasDial event handler
Delegate lpvNotifier, // specifies a handler for RasDial events
ref IntPtr lphRasConn // pointer to variable to receive
// connection handle
);

[DllImport("rasapi32.dll",CharSet=CharSet.Auto)]
public extern static uint RasGetConnectStatus(
IntPtr hrasconn, // handle to RAS connection of interest
[In,Out]RASCONNSTATUS lprasconnstatus
// buffer to receive status data
);

[DllImport("rasapi32.dll",CharSet=CharSet.Auto)]
public extern static uint RasGetErrorString(
uint uErrorValue, // error to get string for
StringBuilder lpszErrorString, // buffer to hold error string
[In]int cBufSize // size, in characters, of buffer
);

[DllImport("rasapi32.dll",CharSet=CharSet.Auto)]
public extern static uint RasConnectionNotification(
IntPtr hrasconn, // handle to a RAS connection
IntPtr hEvent, // handle to an event object
RASNOTIFICATION dwFlags // type of event to receive notifications for
);

public static void RasCheck(uint errorCode)
{
if(errorCode!=(uint)RasError.SUCCESS)
{
// throw new RasException(errorCode);
StringBuilder sb=new StringBuilder(512);
if(RasAPI.RasGetErrorString(errorCode,sb,sb.Capacity)>0)
throw new Exception("Unknow RAS exception.");
// string ret=sb.ToString();
}
}
}
[/code]

Inside class checking internet connection

[code]
public class ConnectionState
{

private enum ConnectionStateEnum
{
//Local system has a valid connection to the Internet, but it might or
might not be currently connected.
ConnectionConfigured = 64,
//Local system uses a local area network to connect to the Internet.
ConnectionLan = 2,
//Local system uses a modem to connect to the Internet.
ConnectionModem = 1,
//No longer used.
ConnectionModemBusy = 8,
//Local system is in offline mode.
ConnectionOffline = 32,
//Local system uses a proxy server to connect to the Internet.
ConnectionProxy = 4,
//Local system has RAS installed.
RasInstalled = 16

}

class Win32
{
[DllImport("Wininet.dll", CharSet=CharSet.Auto)]
public static extern int InternetGetConnectedState(out int Flag, int
Reserved);
}

private static int GetConnectionFlag()
{
int Flag;
Win32.InternetGetConnectedState(out Flag,0);
return Flag;
}

public static bool IsModemConnected()
{
return ((GetConnectionFlag() &
(int)ConnectionStateEnum.ConnectionModem)==0) ?
false : true;
}
}
[/code]

den2005
--
MCP Year 2005, Philippines


"Chris Yager" wrote:

> You have a few options. You can hit your sql database directly via tcp by
> exposing your sql server on the internet and opening port 1433 on your
> firewall. This is obviously not a safe thing to do and I would not
> recommend it but it is possible. If the server is "on the outside"
> (directly connected to the internet) you simply open a sql connection from a
> client program using the ip address of the sql server box as the data
> source. If the sql server is behind a firewall, you need to route packets
> on port 1433 to your sql server.
>
> You could also employ a VPN connection to your sql server using out of the
> box Microsoft components (if you have a windows based network with a domain
> controller). This is a safe option and doesn't require any middle
> components.
>
> -chris
>
> "den 2005" <den2005@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:380788E1-D0B0-4FB3-897B-8BD5772A0C17@xxxxxxxxxxxxxxxx
> > Hi everybody,
> > Is there a client side approach of sending and receiving data from a sql
> > database without a web service or a server component (servicedcomponent
> > and
> > server app)? How can you simulate a network connection over the internet
> > that
> > could send and receive data from and to database?
> > How can you create a network connection that connects to internet for
> > your
> > direct database process would be possible without any server-based
> > components? Please help me.
> > Thanks.
> >
> > denpsia
> > --
> > MCP Year 2005, Philippines
>
>
>
.



Relevant Pages

  • Re: remoting vs. direct sql connection
    ... I'd say that you should never expose your SQL Server directly to the ... Internet -- the security risks are simply far too great. ... Using either a web service or remoting will also somewhat help in relieving ... Remoting logically uses a connection per ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: connecting to SQL Server 2000 from a VB.net app using ADO.net
    ... In terms of connectivity issues over the Internet, firewall ... TCP Ports Needed for Communication to SQL Server ... I can't create a remote connection in Enterprise Manager. ...
    (microsoft.public.sqlserver.connect)
  • Re: Performance of ODBC
    ... Usiing Access front-end to connection a back end through ... the Internet connection is definitely slow with currently affordable network ... Unless you can get a network connection that fast enough and ... that Access is the front end, and the SQL server is the back end. ...
    (microsoft.public.access.adp.sqlserver)
  • Connection problems when internet is down
    ... When the internet goes down, ... general connectivity to SQL Server works one ... I should note the connection problems are even at the ...
    (microsoft.public.sqlserver.odbc)
  • Re: Help!! Creating a RAS _VPN Network connection class - Problem
    ... I don't see where you're checking the return value of the different RAS ... > remote server as verified if internet connection is ok. ... > private void StartWatch() ...
    (microsoft.public.dotnet.framework)

Quantcast