我使用C#中的SQL Server数据库在Visual Studio Community 2013上构建了一个ASP.NET网站。
我想在Microsoft Azure中托管它。我登录Microsoft Azure并在其上发布我的站点。
当我试图从我的数据库中选择行时,我得到了这个错误:
Exception Details: System.ComponentModel.Win32Exception: The system cannot find the file specified [Win32Exception (0x80004005): The system cannot find the file specified]
[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server.我的connectionString是:
string connStr = @"Data Source=(LocalDB)\v11.0;AttachDBFilename=""C:\Users\MyComp\Documents\Visual Studio 2013\Projects\Test\Test\App_Data\MyDB.mdf"";Integrated Security=True";我的数据库有windows身份验证
我需要更改什么以及如何更改才能从db中读取数据?
谢谢!
发布于 2015-12-01 21:45:14
您需要将连接字符串更改为:
Server=tcp:[serverName].database.windows.net;Database=[myDataBase];
User ID=[LoginForDb]@[serverName];Password=[myPassword];Trusted_Connection=False;
Encrypt=True;其中[serverName]是您的服务器名称,依此类推。
发布于 2015-12-01 22:13:30
从连接字符串中,您实际上指向了本地主机上的SQL数据库服务器。
你的Azure web应用将不知道如何定位你的本地主机SQL数据库服务器和附加的DB文件(.mdf)。
这是一种解决方案:
发布于 2015-12-01 23:24:52
一旦您创建了Azure SQL数据库,它将为您提供应用程序所需的连接字符串。转到您的SQL Azure DB的仪表板,在右侧您将看到“显示连接字符串”
为了清楚起见,你不能在Azure Web Apps中使用.mdf数据库,你需要创建一个虚拟机。最佳选择是将Web应用程序与SQL Azure数据库一起使用。
https://stackoverflow.com/questions/34021646
复制相似问题