当前位置:主页>销售管理软件> 列表

使用ADO连接SQLSERVER2000数据库,如何判断S 找erp软件

进销存软件版1楼: 如题[:(][:(][:(]

2楼: 反复尝试,看是否能成功. 如erp软件

3楼: 用
try
连接。。。
except
连接失败
end;

4楼: 连接数据库,抓异常,根据类型判断

5楼: 以下是判断网络是否连通的
Function PingIP(IpAdd:String):Boolean;
type
PIPOptionInformation = ^TIPOptionInformation;
TIPOptionInformation = packed record
TTL: Byte;
TOS: Byte;
Flags: Byte;
OptionsSize: Byte;
OptionsData: PChar;
end;
type PIcmpEchoReply = ^TIcmpEchoReply;
TIcmpEchoReply = packed record
Address: DWORD;
Status: DWORD;
RTT: DWORD;
DataSize:Word;
Reserved: Word;
Data: Pointer;
Options: TIPOptionInformation;
end;
TIcmpCreateFile = function: THandle; stdcall;
TIcmpCloseHandle = function(IcmpHandle: THandle): Boolean; stdcall;
TIcmpSendEcho = function(IcmpHandle:THandle;
DestinationAddress:DWORD;


RequestData: Pointer;
RequestSize: Word;
RequestOptions: PIPOptionInformation;
ReplyBuffer: Pointer;
ReplySize: DWord;
Timeout: DWord): DWord; stdcall;
var
hICMPdll: HMODULE;
hICMP: THANDLE;
IcmpCreateFile : TIcmpCreateFile;
IcmpCloseHandle:TIcmpCloseHandle;
IcmpSendEcho: TIcmpSendEcho;
IPOpt:TIPOptionInformation;
FIPAddress:DWORD;
pReqData,pRevData:PChar;
pIPE:PIcmpEchoReply;
FSize: DWORD;
MyString:string;
FTimeOut:DWORD;
BufferSize:DWORD;
ip:string;
begin
try
hICMPdll := LoadLibrary(''Icmp.dll'');
@ICMPCreateFile:= GetProcAddress(hICMPdll, ''IcmpCreateFile'');
@IcmpCloseHandle := GetProcAddress(hICMPdll, ''IcmpCloseHandle'');
@IcmpSendEcho := GetProcAddress(hICMPdll, ''IcmpSendEcho'');
hICMP := IcmpCreateFile;
Result:=False;
if StrisEmpty(IPAdd) then
Exit;
if HostToIP(ipAdd,IP) then //如果是HOST名称,则解释成IP
IpAdd:=Ip;
FIPAddress:=Inet_Addr(PChar(IPAdd));
if Fipaddress=INADDR_NONE then
Result:=False //地址无效
else
begin
FSize:=80;
BufferSize:=SizeOf(TICMPEchoReply)+FSize;
GetMem(pRevData,FSize);
GetMem(pIPE,BufferSize);
FillChar(pIPE^, SizeOf(pIPE^), 0);
pIPE^.Data := pRevData;
MyString := ''Argen Ping32 Sending Message.'';
pReqData := PChar(MyString);
FillChar(IPOpt, Sizeof(IPOpt), 0);
IPOpt.TTL:= 64;
FTimeOut :=500;
IcmpSendEcho(hICMP, FIPAddress, pReqData, Length(MyString),@IPOpt, pIPE,
BufferSize, FTimeOut);
try
try
if pReqData^ = pIPE^.Options.OptionsData^ then
Result:=True; //地址正常
except
Result:=False; //目标不可到
end;
finally
FreeMem(pRevData);


FreeMem(pIPE);
end;
end; //else
Finally
IcmpCloseHandle(hicmp);
FreeLibrary(hicmpdll);
end;
end;

Function HostToIP(Name:string; var Ip:string):Boolean;
var
wsdata:TWSAData;
hostName:array [0..255] of char;
hostEnt:PHostEnt;
addr:PChar;
begin
WSAStartup ($0101, wsdata);
try
gethostname (hostName, sizeof (hostName));
StrPCopy(hostName, Name);
hostEnt := gethostbyname (hostName);
if Assigned (hostEnt) then
if Assigned (hostEnt^.h_addr_list) then begin
addr := hostEnt^.h_addr_list^;
if Assigned (addr) then begin
IP := Format (''%d.%d.%d.%d'', [byte (addr [0]),
byte (addr [1]), byte (addr [2]), byte (addr [3])]);
Result := True;
end
else
Result := False;
end
else
Result := False
else begin
Result := False;
end;
finally
WSACleanup;

end;
end;
以下是检测数据库是否正常的
try
try
dmPubConn.SQLConnectionShare.Connected:=True;
NetState:=True;
finally
dmPubConn.SQLConnectionShare.Connected:=False;
end
except
on ErrType:Exception do
begin
Self.SpeedButtonLogin.Enabled:=False;
NetState:=False;
if (pos(''08001'',ErrType.Message)*pos(''17'',ErrType.Message))>0 then
MyHint(SysName,''ServerNotExist'')
else
if (pos(''42000'',ErrType.Message)*pos(''4060'',ErrType.Message))>0 then
MyHint(SysName,''DataBaseNotExist'')
else
if (pos(''42000'',ErrType.Message)*pos(''18456'',ErrType.Message))>0 then
MyHint(SysName,''UserNotExist'')

else
begin
MyHint(SysName,''InvalidDriver'');
DrvState:=ExecuteFix(7);
MyHint(SysName,''TryFixed'');
end;
end;
end; //try 1

6楼: 楼上的大哥,我刚学习啊,怎么看得懂你的若干代码,有没有简单些的.[^]

进销存软件版7楼: 不需要看的懂,会用就行,把第一个与第二个函数写到你的软件里,然后
就用 if PingIp(''主机名或者IP地址'') then
通了
else
未能
看数据库服务器(sql 2k)是否启动,用
try
try
dmPubConn.SQLConnectionShare.Connected:=True; //改成你的连接名称
finally
dmPubConn.SQLConnectionShare.Connected:=False;
end
except
on ErrType:Exception do
begin
if (pos(''08001'',ErrType.Message)*pos(''17'',ErrType.Message))>0 then
//服务器不存在或未启动
else
if (pos(''42000'',ErrType.Message)*pos(''4060'',ErrType.Message))>0 then
//设置的数据库不存在
else
if (pos(''42000'',ErrType.Message)*pos(''18456'',ErrType.Message))>0 then
//数据库用户不存在或密码有误
else
begin
//驱动或其他原因的错误
end;
end;
end; //try 1

8楼: levi真不错,可以收我做徒弟吗?
echao2006@163.com

9楼: 到,其实楼上的说的还可以,但是具体实现??????

10楼: 多人接受答案了。