dright dright - 1 year ago 75
C# Question

Database created in SQL Server Management Studios cannot be found by Visual Studio 2010

I created a new database (

) on my localhost in SQL Server 2008 Management Studio.

I'm trying to connect it via connection string in
in Visual Studio 2010 Premium. It won't pick it up.

<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<compilation debug="true" targetFramework="4.0" />
<add name="AC_2012"
connectionString="server=.\SQLEXPRESS;database=AC_2012; integrated security=True;"
providerName="System.Data.SqlClient" />

And here's how I'm trying to call the connection string.. yes it isn't finished..

public static void storedProcedure(string[] paramName, string[] paramValue, string sproc)
SqlConnection conn = null;
SqlDataReader reader = null;

string connStr = ConfigurationManager.ConnectionStrings["AC_2012"].ConnectionString;
conn = new SqlConnection(connStr);
reader = new SqlDataReader();

DataTable dt = new DataTable();

SqlCommand cmd = new SqlCommand(sproc, conn);

for (int x = 0; x < paramName.Count(); x++)
cmd.Parameters.Add(new SqlParameter(paramName[x], paramValue[x]));

reader = cmd.ExecuteReader();

while (reader.Read())
catch (Exception e)

Answer Source

Database names with an underscore _ need to be delimited with square braces [].


connectionString="server=.\SQLEXPRESS;database=[AC_2012]; integrated security=True; "

Alternatively, just don't put an underscore in your database name.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download