解决:无法检索“mvc4.Models.Movie”的元数据。The connection string in the application's configuration file does no

asp.net mvc4添加控制器用到【MovieContext】数据上下文类,出现【无法检索“mvc4.Models.Movie”的元数据。The connection string 'MovieContext' in the application's configuration file does not contain the required providerName attribute."】的问题,解决方法是发现web.config中的

  <connectionStrings>

    <!--注意这里的名称要和数据库的类名称一致,即MovieContext.cs的类名一致-->

    <add name="MovieContext" connectionString="Data Source=.;Initial Catalog=MovieDB;Persist Security Info=True;User ID=sa;password=Adminsa2013" providerName="System.Data.SqlClient" />

</connectionStrings>

缺少providerName="System.Data.SqlClient"属性所致,添加后即可正常运行

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面是一个简单的Java代码实现,具体实现可以根据需求进行修改: ``` import java.io.*; public class DBTest { RandomAccessFile file; int recordSize = 100; // 一个记录的大小 int numRecords; // 记录的数量 public DBTest() throws IOException { file = new RandomAccessFile("products.db", "rw"); // 打开文件 numRecords = (int) (file.length() / recordSize); // 计算记录的数量 } // 添加一条记录 public void addRecord(String name) throws IOException { if (name.length() > 50) { name = name.substring(0, 50); // 只取前50个字符 } StringBuffer buffer = new StringBuffer(name); buffer.setLength(50); // 填充到50个字符 file.seek(file.length()); // 定位到文件末尾 file.writeChars(buffer.toString()); // 写入记录 numRecords++; // 记录数量加1 } // 获取一条记录 public String getRecord(int index) throws IOException { if (index < 0 || index >= numRecords) { return null; } file.seek(index * recordSize); // 计算记录的位置 StringBuffer buffer = new StringBuffer(); for (int i = 0; i < 50; i++) { char c = file.readChar(); // 读取字符 if (c != '\0') { buffer.append(c); // 添加到字符串中 } } return buffer.toString().trim(); // 去掉多余的空格 } // 关闭文件 public void close() throws IOException { file.close(); } public static void main(String[] args) throws IOException { DBTest db = new DBTest(); db.addRecord("Product A"); db.addRecord("Product B"); db.addRecord("Product C"); System.out.println(db.getRecord(0)); // 输出第一条记录 db.close(); } } ``` 上述代码实现了一个简单的产品数据库程序,使用RandomAccessFile类和一个平面文件来存储和检索记录。每个记录由一个字符串名称组成,最多可以包含50个字符。程序包含了添加记录、获取记录和关闭文件的方法。在程序的main方法中,我们向数据库中添加了三条记录,并输出了第一条记录的名称。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值