如何通过局域网访问数据库 [英] how to access database via LAN

查看:55
本文介绍了如何通过局域网访问数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的连接字符串,用于通过LAN连接数据库

This is my connection string to connect the database via LAN

SqlConnection con = new SqlConnection("Data Source=192.168.1.2,1433;Initial Catalog=test;Integrated Security=True;Trusted_Connection=True");



但是这段代码对我不起作用....
错误是

用户"pc名称\来宾"登录失败



but this code not working for me.......
The error is

Login failed for user ''pc name\Guest''

推荐答案

http://www.connectionstrings.com/ [^ ]


我想您正在工作组网络中使用服务器.您无法以Windows身份验证模式连接到服务器.您必须以混合模式安装服务器,并使用帐户名(sa或其他)和密码登录.

使用
server = MACHINE_NAME \ INSTANCE_NAME; uid = sa; pwd = xxx;

连接之前,您还必须执行其他2项操作
1)启用sql浏览器服务
2)转到配置工具"->"SQL Server配置管理器"
选择
SQL Server配置-> [INSTANCE]的协议
并启用TCP/IP(并重新启动服务器)

============================
但是,如果您在域网络上并且已在域控制器上安装了SQL Server,则在添加登录名后可以使用Windows身份验证登录.
要添加登录名,您可以使用
在Windows上使用DEFAULT_DATABASE = [master]创建登录[MACHINE_NAME \ USER_NAME]
I guess you''re using the server in a workgroup network. You cannot connect to the server in windows authentication mode. You must install the server in mixed mode and login using an account name (sa or other) and password.

use
server=MACHINE_NAME\INSTANCE_NAME; uid=sa; pwd=xxx;

There are 2 other things you must do before connecting
1) Enable sql browser service
2) Go to Configuration Tools->SQL Server Configuration Manager
Select
SQL Server Configuration->Protocols for [INSTANCE]
and enable TCP/IP (& restart the server)

==============================
However, if you''re on a domain network & you have installed the SQL Server on the domain controller, you may login using windows authentication after adding logins.
To add logins, you may use
CREATE LOGIN [MACHINE_NAME\USER_NAME] FROM WINDOWS WITH DEFAULT_DATABASE=[master]


检查该PC是否存在登录名和密码.

如果是,则在连接字符串中包括用户名和密码

输入用户ID = sa;
Check if there is login and password for that PC.

If yes then include the UserName and Password in the connection string

Put User ID=sa;


这篇关于如何通过局域网访问数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆