C# 无法访问WCF web数据服务中的数据库

C# 无法访问WCF web数据服务中的数据库,c#,sql,.net,wcf,C#,Sql,.net,Wcf,我无法访问数据库(在实体框架中)。每次我尝试此操作时,它都会显示以下错误: 处理此请求时出错。 我没有得到正确的错误信息,这将帮助我更好地理解 另外,我可以在WCF中使用SqlConnection而不是实体框架吗 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using

我无法访问数据库(在实体框架中)。每次我尝试此操作时,它都会显示以下错误:

处理此请求时出错。

我没有得到正确的错误信息,这将帮助我更好地理解

另外,我可以在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)
        {

        }
    }
}
使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Windows.Forms;
使用AutoSaleClient.ServiceReference;
使用System.Data.Services.Client;
命名空间AutoSaleClient
{
公共部分类登录窗口:表单
{
private System.Windows.Forms.BindingSource booksBindingSource;
公共登录窗口()
{
初始化组件();
}
私有无效按钮1\u单击(对象发送者,事件参数e)
{
DataServiceContext autoSaleContext=新DataServiceContext(新Uri(“http://localhost:3371/AutoSaleDataService.svc/"));
AutoSaleSystemDbEntities db=新的AutoSaleSystemDbEntities(新Uri(“http://localhost:3371/AutoSaleDataService.svc/"));
//db.IgnoreMissingProperties=true;
//_dataContext=new JustBooks_p00002实体(Classes.Utilities.DataServiceAddress);
this.booksBindingSource.DataSource=新的DataServiceCollection(db.Cars.Expand(“CarId”);
//var q=从db中的r开始。RigisterdUsers选择r;
WriteLine(“这是测试”,this.booksBindingSource.ToString());
新建MainForm().Show();
this.Hide();
}
私有void radioButton1_CheckedChanged(对象发送方,事件参数e)
{
}
}
}

在浏览器中查看时,检查AutoSaleDataService.svc是否运行正常如果有任何错误,请删除服务引用并添加新引用并进行检查。

然后需要为dataservicequeryexception添加处理程序,在其周围放置一个try catch并捕获错误消息以获取更多信息