简体   繁体   English

如何从Visual Studio中的网页访问数据库?

[英]How can I access a database from a web page in Visual Studio?

I've read and gone through a number of supposed instructions online but none of them are able to help me with my problem. 我已经在线阅读并阅读了一些假定的说明,但没有一个能够帮助我解决问题。

I'm trying to create a web project that can read from a database and display the values in a table, but every time I try to follow the instructions I find online, I just get errors. 我试图创建一个可以从数据库读取并在表中显示值的Web项目,但是每次我尝试遵循在网上找到的说明时,都会遇到错误。 This is what my project currently looks like: 这是我的项目当前的样子:

https://i.imgur.com/mbNJYNK.png

And when I run it I get this error: 当我运行它时,出现此错误:

https://i.imgur.com/GxlqcdU.png

The database I'm referencing exists in the Server Explorer and has the EMPLOYEE table added. 我要引用的数据库存在于服务器资源管理器中,并添加了EMPLOYEE表。 I've tried manually adding the connectionString to the web.config with the line: 我试过使用以下命令将connectionString手动添加到web.config

<add name="kroger-webpage" connectionString="Data Source=|DataDirectory|\kroger-webpage.mdf" providerName="System.Data.SqlServerCe.4.0"/>

but then I just get the error that the database is corrupted (I'm almost positive it's not.) 但是然后我只是得到数据库已损坏的错误(我几乎肯定不是这样)。

I've been trying to get this to work for hours; 我一直在努力使它工作几个小时。 can someone here help? 这里有人可以帮忙吗?

经过多次尝试和错误,我最终能够通过更改连接字符串来使此工作正常

<add name="kroger-webpage" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\[me]\source\WebSites\WebSite2\App_Data\kroger-webpage.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM