共享主机服务器上的连接字符串
Connection String on a Shared Host Server
我想弄清楚我是否做错了什么。我有一个 MVC5 EF6 项目。我已将它放在共享主机服务器上的 public_html 文件夹中。我创建了一个 MySQL 数据库并为其添加了一个用户。我已确保在项目中包含和引用 MySql.Data.Entity.EF6.dll 和 MySql.Data.dll。
我的 web.config 中有以下连接字符串:
<connectionStrings>
<add name="DefaultConnection" providerName="MySql.Data.MySqlClient" connectionString="server=s023.someserver.com;UserId=shost_admin;Password=1Ycdcamj71Zh;database=shost_MySite;CharSet=utf8;Persist Security Info=True"/>
</connectionStrings>
我尝试了一些方法,我删除了字符集和持久安全信息行,但它仍然不起作用。服务器部分我不是 100% 确定从哪里获得,所以我通过 运行 以下查询从 PHP 我的管理员那里得到它:
SHOW VARIABLES WHERE Variable_name = 'hostname'
在本地,我使用 SQL 服务器数据库进行测试,并且可以正常工作。连接字符串名称相同,所以我知道它试图找到正确的连接字符串,但我觉得我配置错误。
我每次得到的错误信息是:
An error occurred accessing the database. This usually means that the connection to the database failed. Check that the connection string is correct and that the appropriate DbContext constructor is being used to specify it or find it in the application's config file. See http://go.microsoft.com/fwlink/?LinkId=386386 for information on DbContext and connections. See the inner exception for details of the failure.
编辑:
发现问题,我还必须在 web.config 中指定端口和 entitiyframework 部分。
完整答案在这里:http://dev.mysql.com/doc/connector-net/en/connector-net-entityframework60.html
问题是连接字符串没有指定端口。
我想弄清楚我是否做错了什么。我有一个 MVC5 EF6 项目。我已将它放在共享主机服务器上的 public_html 文件夹中。我创建了一个 MySQL 数据库并为其添加了一个用户。我已确保在项目中包含和引用 MySql.Data.Entity.EF6.dll 和 MySql.Data.dll。
我的 web.config 中有以下连接字符串:
<connectionStrings>
<add name="DefaultConnection" providerName="MySql.Data.MySqlClient" connectionString="server=s023.someserver.com;UserId=shost_admin;Password=1Ycdcamj71Zh;database=shost_MySite;CharSet=utf8;Persist Security Info=True"/>
</connectionStrings>
我尝试了一些方法,我删除了字符集和持久安全信息行,但它仍然不起作用。服务器部分我不是 100% 确定从哪里获得,所以我通过 运行 以下查询从 PHP 我的管理员那里得到它:
SHOW VARIABLES WHERE Variable_name = 'hostname'
在本地,我使用 SQL 服务器数据库进行测试,并且可以正常工作。连接字符串名称相同,所以我知道它试图找到正确的连接字符串,但我觉得我配置错误。
我每次得到的错误信息是:
An error occurred accessing the database. This usually means that the connection to the database failed. Check that the connection string is correct and that the appropriate DbContext constructor is being used to specify it or find it in the application's config file. See http://go.microsoft.com/fwlink/?LinkId=386386 for information on DbContext and connections. See the inner exception for details of the failure.
编辑:
发现问题,我还必须在 web.config 中指定端口和 entitiyframework 部分。
完整答案在这里:http://dev.mysql.com/doc/connector-net/en/connector-net-entityframework60.html
问题是连接字符串没有指定端口。