如题,Select HOST_NAME() as FHostName 在查询分析器中完全正常。
但在FieldByName('FHostName').asString中无任何返回值,请朋友看看,是我写错了吗,先谢谢各位了。 with EmpSets.Q_Temp2 do
begin
Close;
SQL.Clear;
SQL.Add(' Select HOST_NAME() as FHostName '); Open; ShowPromptForm('Database'+trim(FieldByName('FHostName').asString)); Close;
end;
但在FieldByName('FHostName').asString中无任何返回值,请朋友看看,是我写错了吗,先谢谢各位了。 with EmpSets.Q_Temp2 do
begin
Close;
SQL.Clear;
SQL.Add(' Select HOST_NAME() as FHostName '); Open; ShowPromptForm('Database'+trim(FieldByName('FHostName').asString)); Close;
end;
ShowPromptForm('Database'+trim(FieldByName('FHostName').asString));<-------??ShowPromptForm???????
用FieldByName('FHostName').asString不行呢?
ShowPromptForm('Database'+trim(Fields[0].asString));
呢??
*如果你用BDE,那么在别名配置里有一个HOST NAME参数,这个参数是告诉SQLServer我以哪个主机名连入SQLServer,通常大家都没有配这个参数,所以你的SQL语句取得的是空串。
*如果你用ADO,ADO的连接字串中有个Workstation ID字段,这个字段设成什么,那么在SQL Server中取得的就是什么(与BDE类似)
---------
综上所述,利用select host_name()取得当前连接的主机名是不可靠的,因为连接者设为什么,它取得的就是什么。
好一点的方法是根据当前的@@spid来取得连接者的网卡号和IP地址,这一般不容易伪装(当然连接者要做什么手脚也是可以的),从master..sysprocess中可以取得这些数据。
应该如SeaWave(NoSound)所说。但确实也太复杂了