这个连接字符串是什么意思?
data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true
具体是什么
AttachDBFilename=|DataDirectory|\aspnetdb.md
意思呢?
data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true
Specifically what does
AttachDBFilename=|DataDirectory|\aspnetdb.md
mean?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这意味着连接将在已发布的应用程序数据目录上打开 aspnetdb.mdb。
这可以避免您在发布后读取网络应用程序内的目录。
Visual Studio 在运行时自动为您执行此操作。
It means that the connection will open aspnetdb.mdb on published app data dir.
This avoid you to read dir inside your web app once published.
Visual Studio does it automatically for you at runtime.
|数据目录| (包含在管道符号中)是指示数据库路径的替换字符串。它消除了对完整路径进行硬编码的需要,这会导致几个问题,因为数据库的完整路径可以在不同的地方序列化。 DataDirectory 还可以轻松共享项目和部署应用程序。
例如,不使用以下连接字符串:
“Data Source= c:\program files\MyApp\Mydb.sdf”
使用 DataDirectory,您可以使用以下连接字符串:
“Data Source = |DataDirectory|\Mydb.sdf”
要设置 DataDirectory 属性,请调用 AppDomain.SetData 方法。如果不设置 DataDirectory 属性,将应用以下默认规则来访问数据库文件夹:
• 对于放置在用户计算机上的文件夹中的应用程序,数据库文件夹使用应用程序文件夹。
• 对于在ClickOnce 下运行的应用程序,数据库文件夹使用创建的特定数据文件夹。
*我忘了添加链接,所以在这里 ->
http://social.msdn.microsoft.com/Forums/en-US/sqlce/thread/dc31ea59-5718-49b6-9f1f-7039da425296/
*
|DataDirectory| (enclosed in pipe symbols) is a substitution string that indicates the path to the database. It eliminates the need to hard-code the full path which leads to several problems as the full path to the database could be serialized in different places. DataDirectory also makes it easy to share a project and also to deploy an application.
For example, instead of having the following connection string:
"Data Source= c:\program files\MyApp\Mydb.sdf"
Using DataDirectory, you can have the following connection string:
“Data Source = |DataDirectory|\Mydb.sdf”
To set the DataDirectory property, call the AppDomain.SetData method. If you do not set the DataDirectory property, the following default rules will be applied to access the database folder:
• For applications that are put in a folder on the user's computer, the database folder uses the application folder.
• For applications that are running under ClickOnce, the database folder uses the specific data folder that is created.
*i forgot to add the link so here ya go ->
http://social.msdn.microsoft.com/Forums/en-US/sqlce/thread/dc31ea59-5718-49b6-9f1f-7039da425296/
*