Я пытаюсь работать через Essential Linq, и у меня есть проблема, просто связанная с файлом .mdf
.Попытка подключения к простейшему файлу mdf
Я сохранил файл на C:\DATA\NORTHWND.MDF
. Я использую Visual Studio 2013
код выглядит следующим образом:
using System;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;
using System.IO;
namespace LinqToSqlWithoutDesigner
{
[Table(Name="Customers")]
class Customer
{
[Column]
public string CustomerID;
[Column]
public string City;
}
class Program
{
static void Main(string[] args)
{
DataContext db = new DataContext(@"C:\DATA\NORTHWND.MDF");
var query = from c in db.GetTable<Customer>()
where c.City == "London"
select new { CustId = c.CustomerID, City = c.City };
foreach(var cust in query)
{
Console.WriteLine(cust);
}
}
}
}
Я также попытался использовать:
string connectionString = @"Data Source=.\SQLEXPRESS;
AttachDbFilename=c:\data\northwind.mdf;
Integrated Security=True;
Connect Timeout=30;
User Instance=True";
DataContext db = new DataContext(connectionString);
Но я всегда получаю ошибку:
Unhandled Exception: System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider:SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
Мое понимание заключается в том, что при выполнении этого он просто создает экземпляр экземпляра sql server на лету. Я могу открыть файл в Sever Explorer просто отлично – Dalupus
Нет, это понимание не является правильным ... Вы должны установить sqlexpress – swe
@Dalupus, если у вас есть только файл .mdf, вы ничего не можете с ним сделать –