如何将本地连接更改为服务器连接数据库 [英] how to local connection change to server connection database

查看:163
本文介绍了如何将本地连接更改为服务器连接数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想部署我的网站,但我的项目在vs2012中使用db,所以当我在服务器中部署我的网站时,我试图部署数据库错误?



我的db是本地bt,当在服务器中发生db连接问题时

i want to deploy my website but my project in vs2012 with db so i am trying to deploy database error occur when i am deploy my site in server?

my db is local bt when in server the db connection problem occurs

推荐答案



处理数据库的系统应该有一个互联网连接,以便部署站点的服务器将通过Internet / Lan访问数据库,并访问该站点。在web配置连接字符串中,只提供您在基因上尝试打开sql的详细信息。试试这个,让我知道结果。请在web配置的 ConnectionString 中提供Ip appdress
Hi,
The system which is handling the database should have an internet connection so that the server in which the site is being deployed will access the db through internet/Lan and the site will be accessed. In the web config connection string just provide the details that u genetally try to open the sql. try this and let me know the result.Please provide the Ip appdress in the ConnectionString of the web config


你能粘贴你的吗?代码在这里?连接字符串必须在配置文件中。

您需要在连接字符串中使用服务器IP更改本地数据库路径。
Can you paste your code here? Coonection string must be in config file.
You needs to change your local db path with server IP in connection string.


| DataDirectory |不是来自配置设置;



|DataDirectory| does not come from config settings;

ConfigurationManager.AppSettings["DataDirectory"]





这来自配置设置;您必须创建并放入项目的.config文件。此特定设置是AppSettings元素中具有键DataDirectory的元素的值。除非您在.config文件中放置一个,否则这不存在。通常,这是您放置永不更改的配置或启动数据的位置。你不应该把文件路径放在这里,因为它们可以在用户安装数据库的机器上有所不同。





This comes from config settings; a .config file you have to create and put into your project. This particular setting is the value of the element with key "DataDirectory" in the AppSettings element. This doesn't exist unless you put one in the .config file. Typically this is where you put configuration or startup data that is never changed. You should not put file paths here, as they can be different on the machine users install your database to.

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)





这是安装应用程序的操作系统定义的当前用户漫游应用程序数据文件夹的路径。你不能改变它,它是由操作系统定义的。您可以确定该文件夹是用户可写的,并且如果用户漫游或从另一台计算机登录,则该文件夹可用。这通常是您想要放置可编辑用户数据的地方。





This is the path to the current user's roaming application data folder defined by the operating system your app was installed on. You cannot change this, it is defined by the OS. You can be sure this folder is writable by the user, and will be available if the user roams, or logs on from another machine. This is typically where you want to put editable user data.

SqlConnection("Data Source=|DataDirectory|\\DatabaseFileName.sdf;...")





这是ADO.NET连接的连接字符串。 ADO.NET专门处理垂直条,它查找与垂直条之间的键名匹配的AppDomain数据。你可以用以下方法获得相同的数据:



AppDomain.CurrentDomain.GetData(DataDirectory)



This is a connection string for an ADO.NET connection. ADO.NET treats vertical bars specially, it looks for an AppDomain data matching the key name between the vertical bars. You can get the same data with:

AppDomain.CurrentDomain.GetData("DataDirectory")


这篇关于如何将本地连接更改为服务器连接数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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