Search code examples
c#databasevisual-studiosql-server-2008r2-express

Connecting Database using c# in Visual Studio 2013


I have a problem connecting my database (created in SQL Server 2008 R2 Express) with c# in vs 2013

Here is the code I wrote

string connStr = ConfigurationManager.ConnectionStrings["newSchool"].ToString();
SqlConnection conn = new SqlConnection(connStr);

the error is NullReferenceException


Solution

  • Where did you define your connection string? In the app.config? Please send us the place where you configure this.

    See http://msdn.microsoft.com/en-us/library/ms254494(v=vs.110).aspx for help.

    See http://www.connectionstrings.com/ how to configure a connection string for .net