在SQL管理工作室创建的数据库无法通过Visual Studio 2010中找到 [英] database created in SQL Management Studios cannot be found by Visual Studio 2010

查看:217
本文介绍了在SQL管理工作室创建的数据库无法通过Visual Studio 2010中找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对我的,在MS SQL Server管理工作室2008年结果本地主机创建一个新的数据库(AC_2012)
我试图通过它连接字符串在web.config中连接在视觉工作室2010 premium。它不会把它捡起来。

 <结构>
  < configSections>
    <! - 有关Entity Framework的配置的详细信息,请访问http://go.microsoft.com/fwlink/?LinkID=237468 - >
    <节名称=的EntityFrameworkTYPE =System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,的EntityFramework,版本4.3.1.0 =文化=中性公钥= b77a5c561934e089/>
  < / configSections>
  <&的System.Web GT;
    <编译调试=真targetFramework =4.0/>
  < /system.web>  <&是connectionStrings GT;
    <添加名称=AC_2012的connectionString =服务器= \\ SQLEX $ P $干燥综合征;数据库= AC_2012;集成安全=真;的providerName =System.Data.SqlClient的/>
  < /&是connectionStrings GT;
< /结构>

和这里就是我正在试图连接调用string..yes还没有完成。

 公共静态无效storeProcedure(字符串[] paramName配置,字符串[] paramValue,字符串存储过程)
{
        康涅狄格州的SqlConnection = NULL;
        SqlDataReader的读卡器= NULL;    尝试
    {
        字符串connStr = ConfigurationManager.ConnectionStrings [AC_2012]的ConnectionString。
        康恩=新的SqlConnection(connStr);
        读者=新SqlDataReader的();        DataTable的DT =新的DataTable();        conn.Open();
        CMD的SqlCommand =新的SqlCommand(存储过程,康涅狄格州);        为(中间体X = 0; X&下; paramName.Count(); X ++)
        {
            cmd.Parameters.Add(新的SqlParameter(paramName配置[X],paramValue [X]));
        }        读者= cmd.ExecuteReader();        而(reader.Read())
        {        }    }
    赶上(例外五)
    ...


解决方案

用下划线 _ 需要用方括号分隔数据库名称[ ]

尝试

的connectionString =服务器= \\ SQLEX $ P $干燥综合征;数据库= [AC_2012];集成安全=真;

或者,只是不要把下划线在你的数据库名称。

I created a new database (AC_2012) on my localhost in MS SQL Server Management Studios 2008.
I'm trying to connect it via connection string in web.config in Visual Studios 2010 Premium. It won't pick it up.

<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  </configSections>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>

  <connectionStrings>
    <add name="AC_2012" connectionString="server=.\SQLEXPRESS;database=AC_2012; integrated security=True; " providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>

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

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

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

        DataTable dt = new DataTable();

        conn.Open();
        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)
    ...

解决方案

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

Try

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

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

这篇关于在SQL管理工作室创建的数据库无法通过Visual Studio 2010中找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆