SQL Server C# 连接 [英] SQL Server c# connection

查看:32
本文介绍了SQL Server C# 连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在我的计算机上的虚拟机中运行 Sql Server 2012,我希望能够使用 Visual Studio 上的 SqlConnection 连接它,但我不知道在 servername 参数上放什么.

So Im running a Sql Server 2012 in a virtual machine on my computer and I want to be able to connect on it with the SqlConnection on Visual Studio, but I have no idea what to put on the servername parameter.

不知道是不是必须把vm ipaddress 或者机器地址"WIN-NIJ53etc\SQLEXPRESS"

I dont know if I have to put the vm ipaddress or the machine address "WIN-NIJ53etc\SQLEXPRESS"

推荐答案

更新:

对于 SQL CE 和 SQL SERVER 之间的迁移:请查看此说明

FOR MIGRATING BETWEEN SQL CE AND SQL SERVER: Please take a look at this instruction here.

您应该按照以下步骤操作:

You should follow these steps:

1- 将虚拟机设置为具有物理 IP 地址.

用于在 Microsoft Virtual PC 上配置网络:http://support.microsoft.com/kb/833134

For configuring network on Microsoft Virtual PC: http://support.microsoft.com/kb/833134

2- 确保您可以看到具有静态 IP 地址的 VM.(ping 是检查这一点的好主意,但不要忘记关闭目标计算机上的防火墙, 我的意思是你想 ping 的机器.服务器不需要看到客户端,所以检查你的客户端(在这种情况下是你的虚拟机)可以像 "ping 192.168.10.1 -t 一样 ping 服务器 IP 地址")

2- Be sure that you can see the VM with a static IP address. (ping is a good idea for checking that, but don't forget to turn off the firewall on the target machine, I mean the machine you wanna ping. There is no need for the server to see the client, so check that your client (in this case your VM) can ping the server IP address like "ping 192.168.10.1 -t")

3- 使用配置管理器(所有程序\Microsoft SQL Server\配置工具)并设置 SQL 端口和网络可见性.

参考:http://msdn.microsoft.com/en-us/library/ms189083(v=sql.105).aspx

4- 重新启动 SQL 服务器.

5- 确保 SQL Server Browser" 服务已启动.(以防您想使用实例名称访问 SQL 服务器)

5- Be sure that "SQL Server Browser" service is started. (incase you wanna use the instance name to access the SQL server)

6- 在主机(具有 SQL 引擎的机器)上配置防火墙并将您在配置管理器中指定的端口添加到 TCP 入站规则.

看看这里:http://www.tavislovell.com/post/How-to-configure-Windows-Firewall-to-allow-access-to-SQL-Server.aspx

但请注意,您应该设置配置管理器中指定的端口(默认为 1433,但有时它是动态的,您应该重新设置)

BUT be advised that you should set the port specified in the Configuration Manager (default is 1433 but sometimes it's dynamic and you should set it again)

7- 设置端口和网络可见性后,您应该将连接字符串中的 "Server" 值更改为这种格式 "IPAddress, PORT" like "192.168.10.50, 1433" (指定端口时,不需要像这样设置实例名"192.168.10.50\SQLEXPRESS")

7- After you set the port and network visibility, you should change the "Server" value in the connection string to this format "IPAddress, PORT" like "192.168.10.50, 1433" (When you specify the port, there is no need to set the instance name like this "192.168.10.50\SQLEXPRESS")

希望能帮到你

这篇关于SQL Server C# 连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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