[MSSQL] 常用預設資料庫('.', LocalDB...)


Posted by mike-hsieh on 2023-10-11

在MSSQL中,開發常使用到本機連線,而本機連線又有幾種,這應該是很常會用到的,但也簡單紀錄。

字串中裡面有一些屬性可以參考這邊文章: [MSSQL] 連線字串常用及冷門屬性介紹

一. SQL Server
  1.1 說明: 微軟的資料庫服務。
  1.2 Server可以使用 . 或是 localhost

connectionString="Data Source=.;Initial Catalog=Northwind;Integrated Security=SSPI;Connection Timeout=6000"

connectionString="Server=localhost;Initial Catalog=Northwind;Persist Security Info=True;User ID=sa;Password=abcd1234;Connection Timeout=6000"

<connectionStrings>
    <add name="ConnectionString" connectionString="Server=localhost;Initial Catalog=Northwind;Persist Security Info=True;User ID=sa;Password=abcd1234;Connection Timeout=6000" providerName="System.Data.SqlClient" />
</connectionStrings>

二. SQL Server express
  2.1 一個資料庫大小有限制
  2.2 僅限制一個CPU運算
  2.3 無 SQL Agent
  2.4 免費
  2.5 Server需使用 .\SQLEXPRESS

connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=SSPI;Connection Timeout=6000"

connectionString="Server=.\SQLEXPRESS;Initial Catalog=Northwind;Persist Security Info=True;User ID=sa;Password=abcd1234;Connection Timeout=6000"

<connectionStrings>
    <add name="ConnectionString" connectionString="Server=.\SQLEXPRESS;Initial Catalog=Northwind;Persist Security Info=True;User ID=sa;Password=abcd1234;Connection Timeout=6000" providerName="System.Data.SqlClient" />
</connectionStrings>

三. Microsoft SQL Server Express LocalDB
  3.1 說明: Visual Studio 自帶的輕量化資料庫,相當於SQL Server Express的輕量版。
  3.2 免費
  3.3 直接使用一個.mdf檔案,相當於 SQLite 輕量化資料庫,可用於開發階段在本機上不需要安裝龐大的MSSQL Server資料庫,或是用於開發測試程式碼時需要涉及到對資料庫的增刪改查操作時,非常實用。
  3.4 當然也可以用SQL Server 連線進去,使用介面查看。
  3.5 Server需使用 (LocalDB)\MSSQLLocalDB

connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=..\Northwind.mdf;Integrated Security=True;Connect Timeout=30;"

<connectionStrings>
    <add name="ConnectionString" connectionString="Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=..\Northwind.mdf;Integrated Security=True;Connect Timeout=30;" providerName="System.Data.SqlClient" />
</connectionStrings>

參考資料:

  1. https://www.cnblogs.com/lucky-donkey/p/13544916.html
  2. https://www.cnblogs.com/lucky-donkey/p/13946290.html

#MSSQL #Database #default #connectionString







Related Posts

Day 157

Day 157

Python Table Manners - 測試 (二)

Python Table Manners - 測試 (二)

GIT branch 分支

GIT branch 分支


Comments