如何将数据库从另一台计算机连接到Visual Studio? [英] How do I connect the database from another computer to visual studio?
问题描述
我在PC1中安装了一个xampp。我的项目是在PC2。我将连接字符串的服务器从localhost更改为:
I have an xampp installed in PC1. My project is in PC2. I changed my connection string's server from localhost into this:
<add name="VoteContext" providerName="MySql.Data.MySqlClient"
connectionString="server=192.168.0.124; database=voting; user id=root;password=;/>
但是当我运行调试我的项目时,它说:
But when I run with debug my project, it says:
PC2 is not allowed to connect to this MariaDB server
我还在PC2中安装了一个xampp,并使用相同的数据库。当我使用这个连接字符串时,
I also have an xampp installed in PC2 with the same db. When I use this connection string,
<add name="VoteContext" providerName="MySql.Data.MySqlClient"
connectionString="server=localhost; database=voting; user id=root;password=;"/>
一切正常。
但是当我将localhost更改为PC2的ipaddress时,
it goes fine.
But when I change the "localhost" into PC2's ipaddress,
<add name="VoteContext" providerName="MySql.Data.MySqlClient"
connectionString="server=192.168.0.123; database=voting; user id=root;password=;"/>
出现相同的错误消息。
我想将我的PC2项目连接到PC1 db。
我已经配置了我的xampp设置httpd-xampp.conf我可以使用PC2(192.168.0.124/phpmyadmin)中的浏览器访问PC1的xampp并且我成功插入了一条记录但是,我无法通过我的visual studio项目连接到PC1服务器。
我尝试了什么:
< add name =VoteContextproviderName =MySql.Data.MySqlClient
connectionString =server = 192.168.0.124;数据库=投票; user id = root; password =; />
the same error message appears.
I'd like to connect my PC2 project to PC1 db.
I already configured my xampp settings httpd-xampp.conf and I can access the xampp of PC1 using my browser in PC2 (192.168.0.124/phpmyadmin) and I successfully inserted a record but still, I couldnt connect to PC1 server with my visual studio project.
What I have tried:
<add name="VoteContext" providerName="MySql.Data.MySqlClient"
connectionString="server=192.168.0.124; database=voting; user id=root;password=;/>
推荐答案
检查远程机器上的配置:可能是MySql安装需要不同的凭证(我会认真的希望如此,数据库上的空白密码不是一个好主意,特别是在管理员帐户上,或者它可能是防火墙。
看看你是否能找到一个工作示例将字符串连接到同一服务器上的不同数据库并复制它。
BTW:通常,您最好指定主机名而不是IP地址因为后者通常在路由器通电时以先来先服务的方式发布。这意味着您无法保证明天x.x.0.124将成为同一个主机!
Check the configuration on the remote machine: it could be the MySql installation requires different credential (and I would seriously hope so, blank passwords on a DB are not a good idea particularly on an "admin" account) or it could be the firewall.
See if you can find a working example connections string to s different DB on the same server and copy that.
BTW: Generally, you'd be better off specifying a Hostname rather than an IP address as the latter are normally issued on a "first come, first served" basis when the router is powered up. Which means that you can't guarantee that "x.x.0.124" will be the same host tomorrow!
这篇关于如何将数据库从另一台计算机连接到Visual Studio?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!