SqlServer通过sql语句访问指定IP地址的数据库

161 阅读1分钟

1.启用 'Ad Hoc Distributed Queries'

exec sp_configure 'show advanced options',1 
	reconfigure 
	exec sp_configure 'Ad Hoc Distributed Queries',1 
	reconfigure

\

2.查询```html

demo:SELECT * FROM OPENDATASOURCE

( 
``````html
'SQLOLEDB','
``````html
DataSource=192.168.120.191;
``````html
User ID=sa;
``````html
Password=123456'
``````html
).FuelDataMgt.dbo.Operator  
```

## 3.关闭 'Ad Hoc Distributed Queries'

```html
exec sp_configure 'Ad Hoc Distributed Queries',0 
	reconfigure 
	exec sp_configure 'show advanced options',0 
	reconfigure
```

\
\