[英]Why cant I create a database with mdf file?
I have a feature in visual studio which I have never really understood. 我在视觉工作室有一个我从未真正理解过的功能。
I am able to 'right-click' on the App_Data folder and then I am able to select 'Sql Server Database'. 我可以在App_Data文件夹上“右键单击”,然后我就可以选择“Sql Server数据库”了。 I dont really understand how I can create a db using just an mdf file?
我真的不明白如何使用mdf文件创建数据库? I thought the sql service was responsible for manipulating these files?
我以为sql服务负责操纵这些文件? And that you have to create the db using the 'sql management studio' interface?
而且你必须使用'sql management studio'界面创建数据库?
Im confised as to how we can essentially just have a lone file and run a db from it for a website? 我很担心我们如何才能拥有一个单独的文件并从网站上运行数据库?
You're application is still connecting through the SQL Server service but it can instruct the service to attach to a specific mdf file at runtime through a connection string. 您的应用程序仍然通过SQL Server服务进行连接,但它可以指示服务在运行时通过连接字符串附加到特定的mdf文件。 eg:
例如:
"Server=.\SQLExpress;AttachDbFilename=c:\mydbfile.mdf;Database=dbname; Trusted_Connection=Yes;"
All SQL Server databases are represented as one (or more) .mdf files and usually .ldf files as well (ldf is the log file, mdf is the data file.) An .mdf file is a file but it is highly structured and maintained by SQL Server. 所有SQL Server数据库都表示为一个(或多个).mdf文件,通常也是.ldf文件(ldf是日志文件,mdf是数据文件。).mdf文件是一个文件,但它是高度结构化和维护的通过SQL Server。 The way SQL Server uses this file is very different from serving up CSV data, as a simple example.
作为一个简单的例子,SQL Server使用此文件的方式与提供CSV数据的方式非常不同。 SQL Server breaks the file into pages and serves the requests for reads and writes via this paging system.
SQL Server将文件分成页面,并通过此分页系统提供读写请求。 It is indeed like a file system within a file system.
它确实像文件系统中的文件系统。 If you think about it it does all make sense.
如果你仔细想想,那一切都有意义。 The data has to get persisted to disk and that disk persistence has to come in the form of a file or files.
数据必须持久保存到磁盘,并且磁盘持久性必须以文件或文件的形式出现。
When you installed Visual Studio you also installed SQL Server Express. 安装Visual Studio时,还安装了SQL Server Express。 This gives you the ability to create and use SQL Server databases.
这使您能够创建和使用SQL Server数据库。
If you were to deploy your application you would then also need to have a SQL Server (Express) install on the web-server you were using (at least because you don't want to use your development database server in production). 如果您要部署应用程序,则还需要在您使用的Web服务器上安装SQL Server(Express)(至少因为您不想在生产中使用开发数据库服务器)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.