App_Data/ASPNETDB.MDF 到 Sql Server 2005(或 08)

发布于 2024-07-16 15:19:18 字数 791 浏览 4 评论 0原文

我一直在开发一个需要帐户登录功能的 ASP.NET WebForms 应用程序(例如注册新用户、更改密码、恢复密码、配置文件、角色等)。 为此,我将 FormsAuthentication 与默认数据存储结合使用,令我惊讶的是,它是 App_Data 中的 MDF 文件。 当需要实际部署这个应用程序时。 在网络上,我将使用一些共享托管,例如 GoDaddy 或其他便宜的公司。

为了提高效率,我想从这个 MDF 切换到实际的 SQL Server 2005 或 2008(谁头脑清醒会使用平面文件?)。 但是,使用共享主机,我将无法运行任何程序,例如 aspnet_regsql.exe。 我只需一个 SQL Server 数据库的登录名和密码,以及一个域根目录中的 FTP 帐户。 没有 MSTSC 远程桌面,没有控制台访问,没有 IIS 中的修补等。

我不需要从 ASPNETDB.MDF 转移任何用户帐户(站点将从零用户开始),但我想如何:

1)轻松当我使用网站管理工具开始使用 FormsAuthentication 时,是否创建 Visual Studio 在 ASPNETDB.MDF 中自动创建的表、过程等?

2) 让 SQL 成员身份提供程序使用我提供的连接字符串,而不是使用现在的任何内容来连接到此 ASPNETDB.MDF。 天哪,我什至在 web.config 中没有看到任何到此 MDF 的连接字符串; 我的应用程序到底怎么样? 甚至找到它? 机器配置? 如果是这样的话,那将是一个糟糕的决定。 这些幕后的废话让我发疯。

非常非常感谢经历过此迁移的人提供的任何帮助!

I've been developing an ASP.NET WebForms app that needed account login functionality (e.g. register new users, change passwords, recover passwords, profiles, roles, etc). To do this, I used FormsAuthentication with the default data store, which, to my surprise, is an MDF file in App_Data. When it comes time to actually deploy this app. live on the web, I'm going to use some shared hosting like GoDaddy or another cheap company.

For efficiency, I'd like to switch over from this MDF to actual SQL Server 2005 or 2008 (who in their right mind uses flat files?). With shared hosting, however, I'm not going to be able to run any programs like aspnet_regsql.exe. I'll just have a single login and password to a SQL Server database, and an FTP account into the domain root. No MSTSC remote desktop, no console access, no tinkering in IIS, etc.

I won't need to transfer any user accounts from ASPNETDB.MDF (site will be starting with zero users), but how am I suppose to:

1) Easily create the tables, procedures, etc. that Visual Studio automatically created in ASPNETDB.MDF when I used Web Site Administration Tool to get started with FormsAuthentication?

2) Have the SQL membership provider use a connection string I give it instead of using whatever it is now to connect to this ASPNETDB.MDF. Hell, I don't even see any connection string to this MDF in the web.config; how the hell is my app. even finding it? Machine.config? That would be a poor decision if that's the case. This behind-the-scenes crap drives me nuts.

Any help from someone who has been through this migration would be very, very much appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

感情洁癖 2024-07-23 15:19:18

.mdf 不是平面文件。 它是一个 SQL Server Express 数据库文件。

有时最好不要在土路上驾驶保时捷......;)

如果您要托管一个具有严重后端的网站,我建议您购买专用服务器。 从管理的角度来看,共享主机有局限性。

为了在 SQL Express 中查找表,有一个名为“management studio”的工具,它随 SQL Server EE 一起提供,它应该允许您访问 .mdf 等中的表。

这是一个到 .mdf 的连接字符串的示例你的 web.config

<connectionStrings>

        <add name="AddressBookConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\AddressBook.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>

</connectionStrings>

我对你的挫败感同身受。 设置和托管一个复杂的网站并不是一件容易的事。 通常,如果您为站点计划任何重要的事情,那么运行向导来配置 Web 应用程序并不是一个好主意,除非您正在学习 Web 应用程序。 如果您要进行专业托管,您需要超越该抽象级别并了解有关如何手动配置/覆盖会员提供商等的更多信息。

希望这能为您指明正确的方向。 祝你好运 ;)

.mdf is not a flat file. It is a SQL server express database file.

Sometimes it is best to not drive a Porsche on a dirt road... ;)

I recommend getting a dedicated server if you are going to host a website with a serious backend. Shared hosting has limits from an admin point of view.

For finding the tables in SQL express, there is a tool called 'management studio' that ships with SQL Server EE that should allow you to get to the tables in the .mdf etc

Here is an example of a connection string to an .mdf in your web.config

<connectionStrings>

        <add name="AddressBookConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\AddressBook.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>

</connectionStrings>

I empathize with your frustration. Setting up and hosting a complex website is no easy task. Usually running wizards to configure a web application is a bad idea if you plan anything serious for the site, unless you are learning about web applications. You need to get past that level of abstraction and learn more about how to manually configure/override the membership provider etc if you are going to be hosting professionally.

Hope this will point you in the right direction. Good luck ;)

游魂 2024-07-23 15:19:18

该 MDF 文件是 SQL Server 数据库。 所有 SQL Server 版本(CE 除外)都使用相同的文件格式,因此任何其他 SQL Server 都可以使用 sp_attach_db 或 SSMS,请参阅如何至:附加数据库 (SQL Server Management Studio)。。 连接到 SQL Server 后,SSMS 可以编写整个数据库的脚本,请参阅如何:生成脚本(SQL Server Management Studio)。 这也可以使用 SMO 以编程方式完成Scripter 对象。 SSMS 脚本将包含数据库中的所有表、索引、过程和所有其他对象。 还有一个 SSMS 中的导入和导出向导,您可以使用用于将表内容(任何数据)导出到 CSV 文件中,然后将此 CSV 文件导入到托管数据库中,但该导入/导出向导相当复杂(它使用 SSIS)。

数据导出的另一种替代方法是使用 bcp 实用程序,请参阅批量导入和批量导出操作

从技术上讲,您可以使用 VS 环境中的 SQL Server Express 实例、使用 sqlcmd 和 bcp 等命令行工具来完成所有这些操作,或许还可以编写自己的 SMO Scripter 应用程序来导出数据库架构。 然而,这需要一定程度的经验。 访问成熟的 Managent Studio 来准备要在托管站点导入的所有数据将变得更加容易。

不要忘记与您的提供商核实他们是否允许恢复或附加您自己的数据库,然后您只需将文件复制到提供商即可轻松摆脱困境。

请注意,您的 MDF 文件只能将其附加到至少与您创建的 SQL Server 版本相同的 SQL Server。 你的VS环境包含一个SQL Server,可能名为SQLEXPRESS,你必须检查它到底是什么版本。 比您的 VS SQL 实例版本更早构建的服务器将拒绝附加您的 MDF 文件,因为它们无法识别该格式。 按照 知识库 321185 中的步骤确定您的 VS 环境的 SQL Server 版本。

更新

我不知道VS有导出向导。 只需按照以下步骤 加里在他提供的链接中提到

That MDF file is a SQL Server database. All SQL Server versions (except CE) use the same file format, so the MDF can be opened by any other SQL Server using sp_attach_db or SSMS, see How to: Attach a Database (SQL Server Management Studio).. Once attached to your SQL Server, SSMS can script out the entire database, see How to: Generate a Script (SQL Server Management Studio). Also this can be done programatically, using the SMO Scripter object. The SSMS script will contain all the table, index, procedure and every other objects in the database. There is also an Import and Export Wizard in SSMS and you can use this to export your tables content (any data) into a CSV file and then import this CSV file into your hosted database, but that import/export wizard is fairly complex (it uses SSIS).

Another alternative for the data export is to use bcp utility, see Bulk Import and Bulk Export Operations.

Tehcnically you can doo all these operations using the SQL Server Express instance in your VS environment, using command line tools like sqlcmd and bcp, and perhaps writing your own SMO Scripter application to export the database schema. However, it requires a certain level of experience. It will be tonnes easier to have access to a fully fledged Managent Studio to preare all the data to be imported at your hosting site.

Don't forget to check with your provider if they allow to restore or attach your own database, then you may get away easy with just a file copy to the provider.

Note that your MDF file will only be possible to attach it to a SQL Server of at least the same version as the one you have created with. You're VS environment contains a SQL Server, probably named SQLEXPRESS, and you must check exactly what version it is. Servers of an earlier build than your VS SQL instance version will refuse to attach your MDF file, since its a format they do no recognize. Follow the steps in KB 321185 to determine what SQL Server version your VS environment has.

Update

I wasn't aware VS has an export wizard. Just follow the steps Gary mentions in the link he provides.

我要还你自由 2024-07-23 15:19:18

一些详细信息会有所不同,具体取决于您的托管提供商,但是:

  1. 如果您尚未执行此操作,请下载并安装Microsoft SQL Server Management Studio Express

  2. 您的托管提供商必须向您提供管理连接信息才能连接到您的 SQL Server 实例。 使用该信息验证您是否可以使用 MSSMSE 进行连接。 如果您不能,那么其​​余的都无关紧要。

  3. 转到此博客 并按照步骤创建所需的数据库脚本以将数据库移至生产环境。 这些脚本可以在 MSSMSE 的查询窗口中运行。

  4. 通常您的连接字符串将存储在 Web.Config 文件中。 连接字符串。 如果正如您在问题中所说,您已经迁移到完整的 SQL Server,您将不想使用“AttachDbFilename=”样式。 您的连接字符串将看起来更像这样:

Some details will be different depending on your hosting provider, but:

  1. If you have not done so already, download and install Microsoft SQL Server Management Studio Express

  2. Your hosting provider will have to provide you the admin connection information to connect to your sql server instance. With that information verify that you can connect using MSSMSE. If you can't then the rest of this won't matter.

  3. Go to this weblog and follow the steps to create the required database scripts to move your database to production. These scripts can be run in the query window of MSSMSE.

  4. Normally your connection string will be stored in the Web.Config file. The connection strings. You will not want to use the "AttachDbFilename=" style if, as you say in your question, you have moved to full SQL Server. Your connection string will look more like this:

    <add name="myConnectionName" connectionString="Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;">

夕嗳→ 2024-07-23 15:19:18

MDF 实际上并不是平面文件数据库,它使用带有 用户实例,以便它可以动态附加数据库。 该引擎是 SQL Server 的有限版本,尽管限制相当高,所以除非您的站点繁忙,否则这不会成为问题。 从此处来看,限制是...

  • 缺乏企业功能支持
  • 限制为 1 个 CPU
  • 缓冲池的 1 GB 内存限制 数据库的
  • 最大大小为 4 GB

连接字符串应位于您的 web.config 中,搜索“AttachDbFileName”(不带引号)。 有关详细信息,请参阅此处

如果您的托管包中有完整的 SQL,通常托管公司会为您提供一个 Web 工具,用于将 MDF 文件(通过指定其路径)附加到完整的 SQL Server 实例。 您可以将 MDF 文件保留在 app_data 文件夹中(因为该文件夹设置了权限,防止匿名用户下载 db 文件)。

连接后使用 SQL Server 标准实例(或其他版本)而不是 SQL Express 用户实例,您只需更改 web.config 文件中的连接字符串以指向您使用 Web 工具配置的数据库实例,而不是使用SQL Express 的自动附加功能。

请参阅此处了解 godaddy 说明。

The MDF isn't actually a flat file database, it uses the SQL Express engine with user instances so it can attach databases on-the-fly. This engine is a limited version of SQL Server, although the limits are quite high so unless you have a busy site it won't be an issue. From here, the limits are...

  • Lack of enterprise features support
  • Limited to one CPU One GB memory
  • limit for the buffer pool Databases
  • have a 4 GB maximum size

The connection string should be in your web.config, search for "AttachDbFileName" (without quotes). For more info see here.

If you have full SQL in your hosting package usually the hosting company gives you a web tool to attach the MDF file (by specifying it's path) to an full SQL server instance. You can just leave the MDF file in the app_data folder (since the folder has permissions set preventing the db file being downloaded by anonymous users).

Once attached to use the SQL Server Standard Instance (or other version) instead of SQL Express user instance you just need to change connection string in the web.config file to point to the database instance that you configured using the web tool rather than using the Auto Attach feature of SQL Express.

See here for the godaddy instructions.

孤凫 2024-07-23 15:19:18

如果您从我运行的新数据开始,这很容易做到

“C:\Windows\Microsoft.NET\Framework\v2.0.50727\a spnet_regsql -C *Data Source=localhost;Initial Catalog=MYDB;Persist Security Info= True;用户ID=;密码=**;" * -A all" 将 ASP.NET 成员资格表和存储过程包含到我选择的数据库中。如果您这样做..请确保覆盖默认的 LocalSQLServer 连接字符串,否则它将在 web.config 中找不到这样的数据库您的 ASP.NET 网站的


<清除>>
<添加名称=“LocalSQLServer”connectionString=“数据源=localhost;初始目录=MYDB;持久安全信息=True;用户ID=**;密码=****;” providerName =“System.Data.SqlClient”/>

This is very easy to do if you are starting with new data

I ran "C:\Windows\Microsoft.NET\Framework\v2.0.50727\a spnet_regsql -C *Data Source=localhost;Initial Catalog=MYDB;Persist Security Info=True;User ID=;Password=**;" * -A all" to include the ASP.NET membership tables and sprocs into the db of my choice. If you do you this..ensure you override the default LocalSQLServer connectionstring or it won't find the db like this in web.config of your asp.net website

<connectionStrings>
<clear/>
<add name="LocalSQLServer" connectionString="Data Source=localhost;Initial Catalog=MYDB;Persist Security Info=True;User ID=**;Password=****;" providerName="System.Data.SqlClient" />

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文