zoukankan      html  css  js  c++  java
  • 初试visual studio2012的新型数据库LocalDB

          今天在vs2012里面打开以前的mvc3项目,结果弹出警告说在vs2012中数据库不建议使用sql server express而是改成用LocalDB。于是就对LocalDB做了一下了解。

        LocalDB是轻型的sql server express,基本能完成后者的作用但是做了大量的简化。我装vs2012的时候是完整安装的,所有的插件都勾选了(提个建议如果是.net开发人员还是把C盘预留大一点的空间吧,我的是70G)。在这种情况下LocalDB已经存在你的电脑上了。

        注意一点如果你的电脑跟我一样是64位的那么该工具是安装到64位的Program Files文件夹下面的而不是Program Files(X86)。找到这个目录C:\Program Files\Microsoft SQL Server\110\Tools\Binn。里面有一个SqlLocalDB.exe文件这就是命令行工具了。

         打开cmd。定位到该目录:输入sqllocaldb.exe /?,出现下面的样子

        

     

         其实你通过上下滚动阅读就会知道概述数据库的基本用法。

         常用的方法:

         任何操作之前都要加sqllocaldb关键字;

         sqllocaldb create mybd 创建一个数据库名字为“mydb”。句尾不用加“;”。

         sqllocaldb start mydb 启用该数据库实例

         sqllocaldb stop mydb 停止该实例

         sqllocaldb delete mydb 删除

         sqllocaldb info mydb 查看数据库信息

         sqllocaldb versions 查看版本

          另外如果在visual studio2012中自己不去指定要用的字符串那么将默认使用LocalDB数据库。可以创建以一个普通的asp mvc3项目。选择internet项目,该项目人默认情况下就会有一个小的数据库来存储用户账号信息。执行代码后,打开web.config.

    <connectionStrings>
        <add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-abc-20120821160659;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-abc-20120821160659.mdf" />
      </connectionStrings>

    从connectionString后面的连接字符串就能看出用的是LocalDB数据库。

  • 相关阅读:
    周末之个人杂想(十三)
    PowerTip of the DaySorting Multiple Properties
    PowerTip of the DayCreate Remoting Solutions
    PowerTip of the DayAdd Help to Your Functions
    PowerTip of the DayAcessing Function Parameters by Type
    PowerTip of the DayReplace Text in Files
    PowerTip of the DayAdding Extra Information
    PowerTip of the DayPrinting Results
    Win7下IIS 7.5配置SSAS(2008)远程访问
    PowerTip of the DayOpening Current Folder in Explorer
  • 原文地址:https://www.cnblogs.com/zhangran/p/2649200.html
Copyright © 2011-2022 走看看