SYBASE查询远程数据回显syb_sendmsg

一般MSSQL可以给我们使用openrowset来返回数据 而SYBASE我们可以使用

syb_sendmsg方法!不过这个方法主要是采用UDP传输数据所以你得开发一个程序监听.OK 那我们首先看看SYBASE的系统设置信息吧!

以下是我copy人家的 默认配置信息

-----------

EXEC sp_configure 'abstract plan cache',0
go
EXEC sp_configure 'abstract plan dump',0
go
EXEC sp_configure 'abstract plan load',0
go
EXEC sp_configure 'abstract plan replace',0
go
EXEC sp_configure 'additional network memory',10240
go
EXEC sp_configure 'allocate max shared memory',0
go
EXEC sp_configure 'allow backward scans',1
go
EXEC sp_configure 'allow nested triggers',1
go
EXEC sp_configure 'allow procedure grouping',1
go
EXEC sp_configure 'allow remote access',1
go
EXEC sp_configure 'allow resource limits',0
go
EXEC sp_configure 'allow sendmsg',0
go
EXEC sp_configure 'allow sql server async i/o',1
go
EXEC sp_configure 'allow updates to system tables',0
go
EXEC sp_configure 'audit queue size',100
go
EXEC sp_configure 'auditing',0
go
EXEC sp_configure 'average cap size',200
go
EXEC sp_configure 'caps per ccb',50
go
EXEC sp_configure 'check password for digit',0
go
EXEC sp_configure 'cis bulk insert array size',50
go
EXEC sp_configure 'cis bulk insert batch size',0
go
EXEC sp_configure 'cis connect timeout',0
go
EXEC sp_configure 'cis cursor rows',50
go
EXEC sp_configure 'cis packet size',512
go
EXEC sp_configure 'cis rpc handling',0
go
--EXEC sp_configure 'configuration file',0,'F:/sybase/sybase_cs.cfg'
--go
EXEC sp_configure 'cpu accounting flush interval',200
go
EXEC sp_configure 'cpu grace time',500
go
EXEC sp_configure 'curread change w/ open cursors',1
go
EXEC sp_configure 'current audit table',1
go
EXEC sp_configure 'deadlock checking period',500
go
EXEC sp_configure 'deadlock pipe active',1
go
EXEC sp_configure 'deadlock pipe max messages',1000
go
EXEC sp_configure 'deadlock retries',5
go
EXEC sp_configure 'default character set id',2
go
EXEC sp_configure 'default database size',8
go
EXEC sp_configure 'default exp_row_size percent',5
go
EXEC sp_configure 'default fill factor percent',0
go
EXEC sp_configure 'default language id',0
go
EXEC sp_configure 'default network packet size',512
go
EXEC sp_configure 'default sortorder id',48
go
EXEC sp_configure 'default unicode sortorder',0,'binary'
go
EXEC sp_configure 'disable character set conversions',0
go
EXEC sp_configure 'disable disk mirroring',1
go
EXEC sp_configure 'disk i/o structures',256
go
EXEC sp_configure 'dtm detach timeout period',0
go
EXEC sp_configure 'dtm lock timeout period',300
go
EXEC sp_configure 'dump on conditions',0
go
EXEC sp_configure 'dynamic allocation on demand',1
go
EXEC sp_configure 'enable cis',1
go
EXEC sp_configure 'enable DTM',0
go
EXEC sp_configure 'enable enterprise java beans',0
go
EXEC sp_configure 'enable file access',0
go
EXEC sp_configure 'enable full-text search',0
go
EXEC sp_configure 'enable HA',0
go
EXEC sp_configure 'enable housekeeper GC',1
go
EXEC sp_configure 'enable java',0
go
EXEC sp_configure 'enable job scheduler',0
go
EXEC sp_configure 'enable ldap user auth',0
go
EXEC sp_configure 'enable monitoring',1
go
EXEC sp_configure 'enable pam user auth',0
go
EXEC sp_configure 'enable real time messaging',0
go
EXEC sp_configure 'enable rep agent threads',0
go
EXEC sp_configure 'enable row level access',0
go
EXEC sp_configure 'enable snmp',0
go
EXEC sp_configure 'enable sort-merge join and JTC',0
go
EXEC sp_configure 'enable ssl',0
go
EXEC sp_configure 'enable surrogate processing',1
go
EXEC sp_configure 'enable unicode conversions',0
go
EXEC sp_configure 'enable unicode normalization',1
go
EXEC sp_configure 'enable webservices',0
go
EXEC sp_configure 'enable xact coordination',1
go
EXEC sp_configure 'enable xml',0
go
EXEC sp_configure 'errorlog pipe active',1
go
EXEC sp_configure 'errorlog pipe max messages',1000
go
EXEC sp_configure 'esp execution priority',8
go
EXEC sp_configure 'esp execution stacksize',34816
go
EXEC sp_configure 'esp unload dll',0
go
EXEC sp_configure 'event buffers per engine',100
go
EXEC sp_configure 'event log computer name',0,'LocalSystem'
go
EXEC sp_configure 'event logging',1
go
EXEC sp_configure 'executable codesize + overhead',60204
go
EXEC sp_configure 'extended cache size',0
go
EXEC sp_configure 'global async prefetch limit',10
go
EXEC sp_configure 'global cache partition number',1
go
EXEC sp_configure 'heap memory per user',4096
go
EXEC sp_configure 'histogram tuning factor',1
go
EXEC sp_configure 'housekeeper free write percent',1
go
EXEC sp_configure 'i/o accounting flush interval',1000
go
EXEC sp_configure 'i/o batch size',100
go
EXEC sp_configure 'i/o polling process count',10
go
EXEC sp_configure 'identity burning set factor',5000
go
EXEC sp_configure 'identity grab size',1
go
EXEC sp_configure 'job scheduler interval',1
go
EXEC sp_configure 'job scheduler tasks',32
go
EXEC sp_configure 'license information',25
go
EXEC sp_configure 'lock address spinlock ratio',100
go
EXEC sp_configure 'lock hashtable size',2048
go
EXEC sp_configure 'lock scheme',0,'allpages'
go
EXEC sp_configure 'lock shared memory',0
go
EXEC sp_configure 'lock spinlock ratio',85
go
EXEC sp_configure 'lock table spinlock ratio',20
go
EXEC sp_configure 'lock wait period',2147483647
go
EXEC sp_configure 'log audit logon failure',0
go
EXEC sp_configure 'log audit logon success',0
go
EXEC sp_configure 'max async i/os per engine',2147483647
go
EXEC sp_configure 'max async i/os per server',2147483647
go
EXEC sp_configure 'max cis remote connections',0
go
EXEC sp_configure 'max concurrently recovered db',0
go
EXEC sp_configure 'max memory',2097151
go
EXEC sp_configure 'max network packet size',6144
go
EXEC sp_configure 'max number network listeners',5
go
EXEC sp_configure 'max online engines',4
go
EXEC sp_configure 'max parallel degree',1
go
EXEC sp_configure 'max scan parallel degree',1
go
EXEC sp_configure 'max SQL text monitored',256
go
EXEC sp_configure 'maximum dump conditions',10
go
EXEC sp_configure 'maximum failed logins',0
go
EXEC sp_configure 'maximum job output',32768
go
EXEC sp_configure 'memory alignment boundary',8192
go
EXEC sp_configure 'memory per worker process',1024
go
EXEC sp_configure 'messaging memory',400
go
EXEC sp_configure 'minimum password length',6
go
EXEC sp_configure 'msg confidentiality reqd',0
go
EXEC sp_configure 'msg integrity reqd',0
go
EXEC sp_configure 'number of alarms',40
go
EXEC sp_configure 'number of aux scan descriptors',200
go
EXEC sp_configure 'number of ccbs',0
go
EXEC sp_configure 'number of checkpoint tasks',1
go
EXEC sp_configure 'number of devices',10
go
EXEC sp_configure 'number of dtx participants',500
go
EXEC sp_configure 'number of dump threads',1
go
EXEC sp_configure 'number of engines at startup',4
go
EXEC sp_configure 'number of histogram steps',20
go
EXEC sp_configure 'number of index trips',0
go
EXEC sp_configure 'number of java sockets',0
go
EXEC sp_configure 'number of large i/o buffers',6
go
EXEC sp_configure 'number of locks',100000
go
EXEC sp_configure 'number of mailboxes',30
go
EXEC sp_configure 'number of messages',64
go
EXEC sp_configure 'number of oam trips',0
go
EXEC sp_configure 'number of open databases',12
go
EXEC sp_configure 'number of open indexes',10000
go
EXEC sp_configure 'number of open objects',50000
go
EXEC sp_configure 'number of pre-allocated extents',2
go
EXEC sp_configure 'number of remote connections',20
go
EXEC sp_configure 'number of remote logins',20
go
EXEC sp_configure 'number of remote sites',10
go
EXEC sp_configure 'number of sort buffers',500
go
EXEC sp_configure 'number of user connections',500
go
EXEC sp_configure 'number of worker processes',0
go
EXEC sp_configure 'o/s file descriptors',100000
go
EXEC sp_configure 'object lockwait timing',1
go
EXEC sp_configure 'open index hash spinlock ratio',100
go
EXEC sp_configure 'open index spinlock ratio',100
go
EXEC sp_configure 'open object spinlock ratio',100
go
EXEC sp_configure 'page lock promotion HWM',200
go
EXEC sp_configure 'page lock promotion LWM',200
go
EXEC sp_configure 'page lock promotion PCT',100
go
EXEC sp_configure 'page utilization percent',95
go
EXEC sp_configure 'partition groups',1024
go
EXEC sp_configure 'partition spinlock ratio',10
go
EXEC sp_configure 'per object statistics active',1
go
EXEC sp_configure 'percent database for history',20
go
EXEC sp_configure 'percent database for output',30
go
EXEC sp_configure 'percent history free',30
go
EXEC sp_configure 'percent output free',50
go
EXEC sp_configure 'performance monitoring option',0
go
EXEC sp_configure 'permission cache entries',15
go
EXEC sp_configure 'plan text pipe active',1
go
EXEC sp_configure 'plan text pipe max messages',1000
go
EXEC sp_configure 'print deadlock information',0
go
EXEC sp_configure 'print recovery information',0
go
EXEC sp_configure 'procedure cache size',102400
go
EXEC sp_configure 'process wait events',1
go
EXEC sp_configure 'read committed with lock',0
go
EXEC sp_configure 'recovery interval in minutes',5
go
EXEC sp_configure 'remote server pre-read packets',3
go
EXEC sp_configure 'row lock promotion HWM',200
go
EXEC sp_configure 'row lock promotion LWM',200
go
EXEC sp_configure 'row lock promotion PCT',100
go
EXEC sp_configure 'runnable process search count',2000
go
EXEC sp_configure 'sampling percent',0
go
EXEC sp_configure 'secure default login',0,'guest'
go
EXEC sp_configure 'select on syscomments.text',1
go
EXEC sp_configure 'send doneinproc tokens',1
go
EXEC sp_configure 'shared memory starting address',0
go
EXEC sp_configure 'size of auto identity column',10
go
EXEC sp_configure 'size of global fixed heap',150
go
EXEC sp_configure 'size of process object heap',1500
go
EXEC sp_configure 'size of shared class heap',1536
go
EXEC sp_configure 'size of unilib cache',0
go
EXEC sp_configure 'SQL batch capture',1
go
EXEC sp_configure 'SQL Perfmon Integration',1
go
EXEC sp_configure 'sql server clock tick length',100000
go
EXEC sp_configure 'sql text pipe active',1
go
EXEC sp_configure 'sql text pipe max messages',1000
go
EXEC sp_configure 'stack guard size',16384
go
EXEC sp_configure 'stack size',41984
go
EXEC sp_configure 'start mail session',0
go
EXEC sp_configure 'statement cache size',0
go
EXEC sp_configure 'statement pipe active',1
go
EXEC sp_configure 'statement pipe max messages',1000
go
EXEC sp_configure 'statement statistics active',1
go
EXEC sp_configure 'strict dtm enforcement',0
go
EXEC sp_configure 'suspend audit when device full',1
go
EXEC sp_configure 'syb_sendmsg port number',0
go
EXEC sp_configure 'systemwide password expiration',0
go
EXEC sp_configure 'tape retention in days',0
go
EXEC sp_configure 'tcp no delay',1
go
EXEC sp_configure 'text prefetch size',16
go
EXEC sp_configure 'time slice',100
go
EXEC sp_configure 'total data cache size',968450
go
EXEC sp_configure 'total logical memory',719811
go
EXEC sp_configure 'total physical memory',719877
go
EXEC sp_configure 'txn to pss ratio',16
go
EXEC sp_configure 'unified login required',0
go
EXEC sp_configure 'upgrade version',12500
go
EXEC sp_configure 'use security services',0
go
EXEC sp_configure 'user log cache size',8192
go
EXEC sp_configure 'user log cache spinlock ratio',20
go
EXEC sp_configure 'wait event timing',1
go
EXEC sp_configure 'xact coordination interval',60
go
EXEC sp_configure 'xp_cmdshell context',1
go

-------

在看看官方的设置资料

syb_sendmsg port number

Summary information

Default value

0

Valid values

0, or 1024-65535, or system limit

Status

Dynamic

Display level

Comprehensive

Required role

System Administrator

The syb_sendmsg port number parameter specifies the port number that Adaptive Server uses to send messages to a UDP (User Datagram Protocol) port with sp_sendmsg or syb_sendmsg.

If more than one engine is configured, a port is used for each engine, numbered consecutively from the port number specified. If the port number is set to the default value, 0 Adaptive Server assigns port numbers.

Sending messages to UDP ports is not supported on Windows NT.

A System Security Officer must set the allow sendmsg configuration parameter to 1 to enable sending messages to UDP ports. To enable UDP messaging, a System Administrator must set allow sendmsg to 1. See "allow sendmsg". For more information on UDP messaging, see sp_sendmsg in the Reference Manual.

allow sendmsg

Summary information

Default value

0 (off)

Valid values

0 (off), 1 (on)

Status

Dynamic

Display level

Comprehensive

Required role

System Security Officer

The allow sendmsg parameter enables or disables sending messages from Adaptive Server to a UDP (User Datagram Protocol) port. When allow sendmsg is set to 1, any user can send messages using sp_sendmsg or syb_sendmsg. To set the port number used by Adaptive Server, see "syb_sendmsg port number".

Sending messages to UDP ports is not supported on Windows NT.

------------------

而我们需要设置的是

EXEC sp_configure 'allow sendmsg',1---默认是0  需要设置的是1

EXEC sp_configure 'syb_sendmsg port number',1--默认是0 我们也把他设置为1 吧!

reconfigure with override  -- 这个不是必须要的!11以后的版本都会动态识别你设置好的参数

以上设置都需要有sso_role权限的!你是sa_role也不行!普通用户的话只能是sso_role权限/sa_role权限其中一种

除非你是sa用户 全部权限都有了~~

以上操作OK了! 那下面我们来执行SQL发送数据

select syb_sendmsg('ip',345,name) from sysobjects

以上语句是 把name字段的数据发送到 某IP的 345端口

以下是官方给出syb_sendmsg的一些资料

syb_sendmsg

说明 仅限于 UNIX 将消息发送到“用户数据报 (UDP) 端口。
语法 syb_sendmsg ip_address, port_number, message
参数
ip_address
是运行 UDP 应用程序的计算机的 IP 地址。
port_number
是 UDP 端口的端口号。
message
是要发送的消息。它最长可达 255 个字符。
示例 示例 1  将消息“Hello”发送到 IP 地址为 120.10.20.5 的端口 3456:
select syb_sendmsg("120.10.20.5", 3456, "Hello")
示例 2 
从用户表中读取 IP 地址和端口号,并使用变量表示要发送的
消息:
declare @msg varchar(255)
select @msg = "Message to send"
select syb_sendmsg (ip_address, portnum, @msg)
from sendports
where username = user_name()
*  系统安全员必须将配置参数 allow sendmsg 设置为 1,才能启用 UDP
用法
消息传送功能。
*  使用
syb_sendmsg 时不执行安全检查。Sybase 强烈建议您不要使用
syb_sendmsg 通过网络发送敏感信息。用户启用此功能,即表示其
接受因使用此功能而导致的任何安全问题。
*  有关创建 UDP 端口的 C 程序示例,请参见
sp_sendmsg。
标准 符合 ANSI SQL 的级别:Transact-SQL 扩展。
权限 任何用户都可以执行 syb_sendmsg。
另请参见 系统过程 sp_sendmsg

syb_sendmsg()发送回来的数据 我们采用这样的程序来接收 以下代码C语言实现

The syb_sendmsg() function requires the addition on two config values. If it
becomes necessary to roll back to a previous ASE version which does not include
syb_sendmsg(), please follow the instructions below.

1. Edit the RUNSERVER file to point to the SWR ASE binary you wish to use.
2. isql -Usa -P<sa password> -Sserver_name -n -iunconfig.sendmsg -ooutput_file

Sample C program

#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <fcntl.h>

main(argc, argv)
int argc; char *argv[];
{

    struct sockaddr_in sadr;
    int portnum,sck,dummy,msglen;
    char msg[256];

    if (argc <2) {
        printf("Usage: udpmon <udp portnum>/n");
        exit(1);
    }

    if ((portnum=atoi(argv[1])) <1) {
        printf("Invalid udp portnum/n");
        exit(1);
    }

    if ((sck="socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP))" < 0) {
        printf("Couldn't create socket/n");
        exit(1);
    }

    sadr.sin_family      = AF_INET;
    sadr.sin_addr.s_addr = inet_addr("0.0.0.0");
    sadr.sin_port        = portnum;

    if (bind(sck,&sadr,sizeof(sadr)) < 0) {
        printf("Couldn't bind requested udp port/n");
        exit(1);
    }

    for (;;)
    {

        if((msglen="recvfrom(sck, msg, sizeof(msg), 0, NULL, &dummy))" < 0)
            printf("Couldn't recvfrom() from udp port/n");

        printf("%.*s/n", msglen, msg);
    }
}

posted on 2007-08-22 01:26  springside例子  阅读(618)  评论(0编辑  收藏  举报