本机的Sql Express .mdf上传到服务器后无法访问的情况。

nanhe0065 2007-06-28 02:57:31
在本机上做了一个极简单的应用。添加新项:Sql数据库, 在App_Data目录下生成一个DataBase.mdf文件。在此mdf文件里建了一个表,输入了一些数据。然后在服务器资源管理器上直接拖拽到Form上生成GridView。在本机上一切正常。

等上传到服务器上,建好虚拟目录后再访问,提示:
在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: SQL 网络接口, error: 26 - 定位指定的服务器/实例时出错)
...
------
本机生成的web.config里的连接字符串:
<connectionStrings>
<add name="DatabaseConnectionString1" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>


以为这应该像是用Access的mdb文件一样轻松才对,结果好郁闷~

...全文
491 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
nanhe0065 2007-06-28
  • 打赏
  • 举报
回复
应该是手动附加.mdf~

总之,郁闷的很。
nanhe0065 2007-06-28
  • 打赏
  • 举报
回复
照这么讲Sql Express的auto attach功能不好用啊。

我也是手动Attach后,再把web.config里的连接字符串改成
Data Source=.\SQLEXPRESS;Initial Catalog=***;Integrated Security=True
后才能进行访问。

折腾了一晚上!结果最后还是得手动附加.mdb,实在郁闷~
namhyuk 2007-06-28
  • 打赏
  • 举报
回复


Here is another interesting error message while trying to use the auto-attach feature of the SQL Server 2005:



An attempt to attach an auto-named database for file C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\WebSites\WebSite1\App_Data\aspnetdb.mdf failed. A database with the same name exists, or specified file cannot be Opened, or it is located on UNC share.



There are several reasons for the above error. In most cases, it has nothing to do with the last part of the error message - "A database with the same name exists, or specified file cannot be Opened, or it is located on UNC share".

Here is some work arounds to get rid of the above error message:

1. Open SQL Server Management Studio and attach the .mdf file manually to the SQL Server. (Select the 'Databases' node, Right click and select 'Attach')

Now change your web.config and change the connection string to point to the pre attached database instead of auto attach.

2. SQLExpress creates a directory per user in "c:\Documents and Settings\[user name]\Local Settings\Application Data\Microsoft\Microsoft SQL Server Data\SQLEXPRESS" to store some information. Delete this directory and try again.

3. The windows account "ASPNET" must have write permission on the folder. If it is a Windows 2003 machine, provide write access to the account "NETWORK SERVICE" on the folder, instead of account ASPNET.

4. You may want to disable the "User Instance=true" and try.

5. Are you using beta versions of VWD, Visual Studio 2005 or SQL Server 2005 Express? Uninstall them and install the released versions.

6. User Instance=True will work only if your SQL Server 2005 Express is using Windows Authentication mode. It will fail if you are using mixed mode. (Select the computer name in the SQL Server Management Studio, right click and select 'Properties'. Select the node 'Security' to view/change the authentication mode)

7. Make sure your connection string is correct. It must be something like below:

"Data Source=.\SQLExpress;Persist Security Info=True;Integrated Security=SSPI;Initial Catalog=YourUserId_DatabaseName"

When you use Integrated Secuiryt=SSPI in the connection string, make sure you are using <identity impersonate="true" /> in the <system.web> section of the web.config and also make sure to specify a valid windows account for the "Anonymous User" access section in IIS.
nanhe0065 2007-06-28
  • 打赏
  • 举报
回复
又出现状况了,提示:
Unable to open the physical file "C:\XXX\App_Data\Database.mdf". Operating system error 5: "5(拒绝访问。)".
An attempt to attach an auto-named database for file C:\XXX\App_Data\Database.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

痛苦啊~
namhyuk 2007-06-28
  • 打赏
  • 举报
回复
1、服务器上必须装有Sql Server Express。
2、Sql Server外围用应服务器->服务和连接的外围应用服务器->SQLEXPRESS->远程连接->选择:本地接连和远程连接,同时使用TCP/IP和named pipes.
有一个资源设置分数错了,设了10分,抱歉,但没法改分数了,这个是5分的。那个资源请不要下载,我会注上说明,不好意思AzaChat管理系统Powered by DDD & King ZD系统功能:登录,注册,群聊,私聊,踢人,聊天字体设置,字体颜色,图片插入,图文混编,音效播放,抖动窗体(模仿QQ)聊天人员管理,数据库管理,数据库查找功能皮肤更换功能系统说明:这个系统是我这个学期课程设计,花了我将近一个多月的时间(期末考试阶段,很忙 - -#),在写之前,我完全不懂数据库和网络传输,C#和面向对象思想也是这学期刚开的。虽然Bug还很多,但我仍然写出来了,很是开心。上传到CSDN,希望对大家有帮助Aza的来源是因为一个笑话,一个女人是500只鸭子,我想到聊天室就应该那种AzaAza的聊天声音,嘿嘿代码我给,论文自己写。。。看懂了别人的代码就是你的,看不懂,还是我的。。。写了很多注释,相信对大家有帮助的版本:我实在VS2008下面开发的,下载包里面自带转换器可以将项目文件转换到VS2005Sql server的版本是vs自带的sql server 2005 express数据库说明:将自带的两个数据库文件User.mdf和Server_log附加到数据库将数据库登录方式打开为Windows身份验证和Sql Server验证sa的密码可以自己改如果想在数据库服务器和聊天服务器分开的话,必须将数据库服务器的远程连接选项打开更详细的设置方式可以去查CSDN服务器帐号:sa密码:123456管理员帐号:admin密码:admin用户帐号:123密码:123更多帐号可以注册和去服务器端管理客户端普通帐号可以随时注册服务器端必须是管理员帐号登录用起来很简单,登录进去就知道了。PS:程序在.Net Framework2.0下写,请确保电脑已经有.Net Framework2.0或者更高版本,否则会报错Powered by DDDE-mail:alswlwangzi@163.com2008.7.112008.7.11更新..........................................................................................................................................更新内容:V1.3版本更新:修改图片传输大小限制Bug,增强数据管理删选功能,修改在线用户查看,增加查看对方IP地址和连接端口功能V1.2"版本更新:加入远程数据库登录管理功能V1.1版本更新:加入服务器数据管理,修改增加删除数据保存的一些Bug
《数据库系统原理》 实验报告 班级________ 姓名________________ 学号___________ 信息与电子工程学院 实验1 sql server 熟悉和数据库创建 "实验目的 " "熟悉sql server " "2005提供的服务管理器、企业管理器、查询分析器、客户端和服务器端网络" "实用工具等常用管理工具的使用。理解客户/服务器模式,理解面向连接与 " "非面向连接的差别。理解交互式sql的工作机制。能够理解命名管道协议与t" "cp/ip协议的差别。能够登陆上sql server数据库服务器。 " "实验内容 " "1、启动sql server 服务。 " "2、打开sql server的企业管理器,连接上sql server服务器。展开左边 " "树状窗口的各级结点,观察右边内容窗口的变化。 " "3、打开sql server的查询分析器,用use命令打开样例数据库pubs。 " "4、在查询窗口输入exec sp_help,运行后察看结果。 " "5、在查询窗口输入select * from authors ,运行后察看结果。 " "三、实验结果 " "3、当不确定当前所操作的是哪个数据库,可使用use来定位到某数据库。 " "4、 " " " "查询某张表的所有列。 " 实验2 简单查询 "实验目的: " "熟悉sql " "server的企业管理器和查询分析器的用户界面,掌握用企业管理器和查询分" "析器创建数据库,修改数据库和删除数据库的方法。 " "实验内容 " "分别使用sql server " "2005企业管理器和t—sql语句,按下列要求创建、修改和删除用户数据库。 " "1、创建名称为company的数据库,数据库中包含一个数据文件,逻辑文件名" "为company_data,磁盘文件名为company_data.mdf,文件初始容量为5mb, " "最大容量为15mb,文件容量递增值为1mb;事务日志文件的逻辑文件名为com" "pany_log,磁盘文件名为company_log.ldf,文件初始容量为5mb,最大容量" "为10mb,文件容量递增值为1mb。 " "2、对该数据库进行修改:添加一个数据文件,逻辑文件名为company2_data" ",磁盘文件名为company2_data.ndf,文件初始容量为1mb,最大容量为5mb " ",文件容量递增值为1mb;将日志文件company_log的最大容量增加为15mb," "文件容量递增值为2mb。 " "3、 " "在company数据库中添加一个文件组tempgroup,并向该文件组中添加一个容" "量为3mb,最大容量为10mb,递增量为1mb的数据文件,该数据文件的逻辑文" "件名为company3_data,磁盘文件名为company3_data.ndf。 " "4、在company数据库中删除数据文件company2_data。 " "删除数据库company。 " "采用默认设置创建数据库company。 " "三、实验结果 " "1、create database company " "on ( name=company_data, " "filename='d:\microsoft sql " "server\mssql10_50.sqlexpress\mssql\data\company_data.mdf', " "size=5mb, " "maxsize=15mb, " "filegrowth=1mb ) " "log on (name=company_log, " "filename='d:\microsoft sql " "server\mssql10_50.sqlexpress\mssql\data\company_log.ldf', " "size=5mb, " "maxsize=10mb, " "filegrowth=1mb ); " "2、alter database company " "add file " "(name=company2_data, " "filename='d:\microsoft sql " "server\mssql10_50.sqlexpress\mssql\data\company2_data.mdf', " "size=1mb, " "maxsize=5mb, " "filegrowth=1mb) " "alter database company " "modify file " "(name='company_log',maxsize=15mb,filegrowth=2mb); " "3、alter database company " "a

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧