I made very simple application in WPF using MVVM pattern.
All data in SQL Server 2012 and I use Entity Framework code-first to manipulate it.
But when I start application, it starts very slow and shows this error:
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
Also I have my ViewModel
in App.xaml
specified like this:
<viewModel:MainViewModel x:Key="MainViewModel"/>
and this line is underlined with above error.
DataContext:
DataContext="{StaticResource MainViewModel}"
UPD
VieModel class
class MainViewModel : ViewModelBase
{
public BookContext db;
public Book book;
public ObservableCollection<Book> Books { get; set; }
public MainViewModel()
{
db = new BookContext();
db.Books.Load();
Books = new ObservableCollection<Book>(db.Books);
simpleCommand = new RelayCommand(DoSimpleCommand);
}
public int ID
{
get { return book.ID; }
set
{
if (value == book.ID) return;
book.ID = value;
RaisePropertyChanged();
}
}
public string Title
{
get { return book.Title; }
set
{
if(value==book.Title) return;
book.Title = value;
RaisePropertyChanged();
}
}
public string Author
{
get { return book.Author; }
set
{
if(value==book.Author) return;
book.Author = value;
RaisePropertyChanged();
}
}
public int Count
{
get { return book.Count; }
set
{
if(value==book.Count) return;
book.Count = value;
RaisePropertyChanged();
}
}
private RelayCommand simpleCommand;
public ICommand SimpleCommand
{
get { return simpleCommand; }
}
private void DoSimpleCommand()
{
MessageBox.Show("Button is Clicked");
}
public override void Cleanup()
{
db.Dispose();
}
}