0
我無法訪問數據庫(在實體框架中)。每次嘗試時,都會顯示此錯誤:無法在WCF Web數據服務中訪問數據庫
處理此請求時發生錯誤。
我沒有得到正確的錯誤信息,這會幫助我更好地理解。
另外,我可以在WCF中使用SqlConnection而不是實體框架嗎?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AutoSaleClient.ServiceReference;
using System.Data.Services.Client;
namespace AutoSaleClient
{
public partial class LoginWindow : Form
{
private System.Windows.Forms.BindingSource booksBindingSource;
public LoginWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
DataServiceContext autoSaleContext = new DataServiceContext(new Uri("http://localhost:3371/AutoSaleDataService.svc/"));
AutoSaleSystemDbEntities db = new AutoSaleSystemDbEntities(new Uri("http://localhost:3371/AutoSaleDataService.svc/"));
// db.IgnoreMissingProperties = true;
// _dataContext = new JustBooks_P000002Entities(Classes.Utilities.DataServiceAddress);
this.booksBindingSource.DataSource = new DataServiceCollection<Car>(db.Cars.Expand("CarId"));
// var q = from r in db.RigisterdUsers select r;
Console.WriteLine("this is test ",this.booksBindingSource.ToString());
new MainForm().Show();
this.Hide();
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
}
}
}
然後,您需要爲dataservicequeryexception添加一個處理程序,試着抓住它並捕獲錯誤消息以獲取更多信息 –