<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Visual Studio Learn</title>
    <description>The latest articles on DEV Community by Visual Studio Learn (@visualstudiolearn).</description>
    <link>https://dev.to/visualstudiolearn</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4221287%2F459827c7-0870-405c-94db-087d6bf8b535.png</url>
      <title>DEV Community: Visual Studio Learn</title>
      <link>https://dev.to/visualstudiolearn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/visualstudiolearn"/>
    <language>en</language>
    <item>
      <title>How Do I Connect SQL Server to Visual Studio? Three Ways — Server Explorer, Object Explorer &amp; Connected Services (2026)</title>
      <dc:creator>Visual Studio Learn</dc:creator>
      <pubDate>Wed, 04 Nov 2026 09:36:44 +0000</pubDate>
      <link>https://dev.to/visualstudiolearn/how-do-i-connect-sql-server-to-visual-studio-three-ways-server-explorer-object-explorer--4m49</link>
      <guid>https://dev.to/visualstudiolearn/how-do-i-connect-sql-server-to-visual-studio-three-ways-server-explorer-object-explorer--4m49</guid>
      <description>&lt;p&gt;You connect Visual Studio to SQL Server three ways — &lt;strong&gt;Server Explorer&lt;/strong&gt; for a design-time connection, &lt;strong&gt;SQL Server Object Explorer&lt;/strong&gt; to browse and query the way you would in SSMS, and &lt;strong&gt;Connected Services&lt;/strong&gt; to wire the database into a project so your code can use it. All three are below, click by click, on Visual Studio 2022 17.14.44 with SQL Server 2025 — including the one encryption error that stops almost everyone the first time.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Versions used in this tutorial&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Visual Studio 2022 — &lt;strong&gt;17.14.44&lt;/strong&gt; (released October 29, 2026)&lt;/li&gt;
&lt;li&gt;SQL Server &lt;strong&gt;2025 (17.x)&lt;/strong&gt; — Enterprise Developer edition (free for development and testing)&lt;/li&gt;
&lt;li&gt;SQL Server Management Studio &lt;strong&gt;22.11.3&lt;/strong&gt; (for the comparison section)&lt;/li&gt;
&lt;li&gt;Microsoft.Data.SqlClient &lt;strong&gt;6.1.7&lt;/strong&gt; (the LTS line, supported until August 14, 2028)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On Visual Studio 2026? Same three tools, same clicks — this walkthrough is captured on 2022, which is still fully supported, and everything below works identically in the newer IDE.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Before you start: set up your environment from zero
&lt;/h2&gt;

&lt;p&gt;Nothing here assumes you already have anything installed. We install Visual Studio with the right workloads, a real SQL Server you control, and SSMS — then verify all of them before connecting anything.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1 — Visual Studio 2022 with the data workloads
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Download &lt;strong&gt;Visual Studio 2022 Community&lt;/strong&gt; (free) from Microsoft and run the Visual Studio Installer.&lt;/li&gt;
&lt;li&gt;On the &lt;strong&gt;Workloads&lt;/strong&gt; tab, tick:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Data storage and processing&lt;/strong&gt; — brings SQL Server Data Tools (SSDT) and SQL Server Express LocalDB. Without it, two of the three methods below do not exist in your IDE.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;.NET desktop development&lt;/strong&gt; — for the demo project in Method 3.&lt;/li&gt;
&lt;li&gt;Optional: &lt;strong&gt;Azure development&lt;/strong&gt;, only for the Azure SQL path in Method 3.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Install&lt;/strong&gt;, launch Visual Studio, and verify: &lt;strong&gt;View → SQL Server Object Explorer&lt;/strong&gt; exists. (Minimums: 64-bit Windows 11, 4 GB RAM — 16 GB recommended — and 20–50 GB free disk for a typical install.)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Step 2 — SQL Server 2025 Developer edition
&lt;/h3&gt;

&lt;p&gt;LocalDB (from Step 1) covers Methods 1 and 3, but Method 2 deserves a real server. New in SQL Server 2025, there are &lt;strong&gt;two&lt;/strong&gt; free Developer editions: &lt;strong&gt;Enterprise Developer&lt;/strong&gt; (every Enterprise feature) and &lt;strong&gt;Standard Developer&lt;/strong&gt; (every Standard feature). Pick Enterprise Developer for a general dev machine; pick Standard Developer when production runs Standard, so no Enterprise-only feature sneaks into your schema. Both are free — no key, no subscription — licensed for development and testing, not production.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;On Microsoft's SQL Server downloads page, choose &lt;strong&gt;Developer → Enterprise Developer&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Run setup → &lt;strong&gt;Installation → New SQL Server standalone installation&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;At &lt;strong&gt;Instance Configuration&lt;/strong&gt;, keep the default instance or name yours — write the name down; you will type it into connection dialogs exactly.&lt;/li&gt;
&lt;li&gt;At &lt;strong&gt;Server Configuration&lt;/strong&gt;, set the &lt;strong&gt;SQL Server Database Engine&lt;/strong&gt; service to start &lt;strong&gt;automatically&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;At &lt;strong&gt;Database Engine Configuration → Authentication Mode&lt;/strong&gt;, choose deliberately: &lt;strong&gt;Windows authentication mode&lt;/strong&gt; is enough for this whole post and is the safer default; &lt;strong&gt;Mixed Mode&lt;/strong&gt; additionally enables SQL logins such as &lt;code&gt;sa&lt;/code&gt; — pick it only if you actually need them. You are choosing your server's security shape, not ticking a box.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Add Current User&lt;/strong&gt; so your Windows account is a SQL Server administrator, then &lt;strong&gt;Install&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Verify in &lt;strong&gt;Services&lt;/strong&gt;: your instance is &lt;strong&gt;Running&lt;/strong&gt;. (Needs Windows 10 or later, 4 GB RAM recommended, 6 GB free disk.)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Step 3 — SSMS 22 (for the comparison later)
&lt;/h3&gt;

&lt;p&gt;Download &lt;strong&gt;SQL Server Management Studio 22&lt;/strong&gt; (latest: 22.11.3) from Microsoft — a separate free tool, installed through the Visual Studio Installer — and connect it to the same instance. We will put it side by side with Visual Studio near the end.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4 — Verify everything
&lt;/h3&gt;

&lt;p&gt;In a terminal, run &lt;code&gt;sqllocaldb info&lt;/code&gt;. You should see &lt;strong&gt;MSSQLLocalDB&lt;/strong&gt; — the automatic LocalDB instance, owned by your Windows user, starting on demand. LocalDB is a lightweight developer edition of SQL Server Express: user mode, no service to manage, Windows-only. The Developer instance is verified in Services above. Two green checks — now the three methods.&lt;/p&gt;

&lt;h2&gt;
  
  
  Method 1 — Server Explorer: the design-time connection
&lt;/h2&gt;

&lt;p&gt;The oldest way in, and still the fastest way to attach a database to a project for design-time work.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open &lt;strong&gt;View → Server Explorer&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Connect to Database&lt;/strong&gt; in the toolbar (or right-click &lt;strong&gt;Data Connections → Add Connection&lt;/strong&gt;).&lt;/li&gt;
&lt;li&gt;In &lt;strong&gt;Choose Data Source&lt;/strong&gt;, select &lt;strong&gt;Microsoft SQL Server&lt;/strong&gt; → OK. (Different source preselected? Use &lt;strong&gt;Change&lt;/strong&gt;.)&lt;/li&gt;
&lt;li&gt;In &lt;strong&gt;Add Connection&lt;/strong&gt;: &lt;strong&gt;Server name&lt;/strong&gt; &lt;code&gt;(localdb)\MSSQLLocalDB&lt;/code&gt;; &lt;strong&gt;Authentication:&lt;/strong&gt; Windows Authentication; &lt;strong&gt;database:&lt;/strong&gt; pick one from the drop-down.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Test Connection&lt;/strong&gt;. The success message is the fastest honest check that your server name and login are both right.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;OK&lt;/strong&gt; and expand the connection under &lt;strong&gt;Data Connections&lt;/strong&gt; to browse tables.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;One thing old tutorials never showed: in designer flows, Visual Studio saves this connection's string into your project's configuration (the &lt;code&gt;connectionStrings&lt;/code&gt; section of App.config). That string — not the tree node — is what your application actually uses, which is why the decoding section below matters.&lt;/p&gt;

&lt;h2&gt;
  
  
  Method 2 — SQL Server Object Explorer: SSMS inside Visual Studio
&lt;/h2&gt;

&lt;p&gt;If Server Explorer is a connection, Object Explorer is a workplace. It requires SSDT from Step 1 and deliberately mirrors the SSMS tree.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open &lt;strong&gt;View → SQL Server Object Explorer&lt;/strong&gt; (shortcut: &lt;strong&gt;Ctrl+\, Ctrl+S&lt;/strong&gt;).&lt;/li&gt;
&lt;li&gt;Right-click the &lt;strong&gt;SQL Server&lt;/strong&gt; node → &lt;strong&gt;Add SQL Server&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;In the &lt;strong&gt;Connect&lt;/strong&gt; dialog, enter your Developer instance's server name (machine name for a default instance, &lt;code&gt;HOST\INSTANCE&lt;/code&gt; for a named one), keep &lt;strong&gt;Windows Authentication&lt;/strong&gt;, click &lt;strong&gt;Connect&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Expand the instance → &lt;strong&gt;Databases&lt;/strong&gt; — tables, views and stored procedures in the same hierarchy SSMS shows.&lt;/li&gt;
&lt;li&gt;Right-click a database → &lt;strong&gt;New Query&lt;/strong&gt; and run real T-SQL:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;dbo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;DemoCustomers&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;CustomerId&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt; &lt;span class="k"&gt;IDENTITY&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;FullName&lt;/span&gt; &lt;span class="n"&gt;NVARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;City&lt;/span&gt; &lt;span class="n"&gt;NVARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;dbo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;DemoCustomers&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;FullName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;City&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;VALUES&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;N&lt;/span&gt;&lt;span class="s1"&gt;'Amara'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;N&lt;/span&gt;&lt;span class="s1"&gt;'Toronto'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;N&lt;/span&gt;&lt;span class="s1"&gt;'Jonas'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;N&lt;/span&gt;&lt;span class="s1"&gt;'Berlin'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;N&lt;/span&gt;&lt;span class="s1"&gt;'Priya'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;N&lt;/span&gt;&lt;span class="s1"&gt;'Lagos'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;CustomerId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;FullName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;City&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;dbo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;DemoCustomers&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(The companion code folder at the end contains this exact script as &lt;code&gt;setup.sql&lt;/code&gt;, so the post, the video and the code can never drift apart.)&lt;/p&gt;

&lt;h2&gt;
  
  
  Method 3 — Connected Services: wire the database into a project
&lt;/h2&gt;

&lt;p&gt;Methods 1 and 2 connect &lt;em&gt;you&lt;/em&gt; to the database. Connected Services connects &lt;em&gt;your project&lt;/em&gt; — package references added, connection string stored properly, dependency registered.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In &lt;strong&gt;Solution Explorer&lt;/strong&gt;, right-click the &lt;strong&gt;Connected Services&lt;/strong&gt; node → &lt;strong&gt;Add&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Choose &lt;strong&gt;SQL Server Database&lt;/strong&gt;. The Connect to dependency page offers four targets: &lt;strong&gt;SQL Server Express LocalDB&lt;/strong&gt;, &lt;strong&gt;SQL Server Database in a local container&lt;/strong&gt;, &lt;strong&gt;SQL Server Database (on-premises, local network)&lt;/strong&gt;, and &lt;strong&gt;Azure SQL Database&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Pick &lt;strong&gt;SQL Server Express LocalDB&lt;/strong&gt; → the &lt;strong&gt;MSSQLLocalDB&lt;/strong&gt; instance.&lt;/li&gt;
&lt;li&gt;For connection-string storage, choose the &lt;strong&gt;local secrets file&lt;/strong&gt; — never a source file (the decoding section explains why).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Next → Finish.&lt;/strong&gt; When the wizard completes, it stores the string in the local secrets file from Step 4 and the dependency appears under &lt;strong&gt;Service Dependencies&lt;/strong&gt;. One honest warning from this tutorial's own capture session: on our machine the wizard stopped at that last step — &lt;strong&gt;"Failed to configure Secrets store"&lt;/strong&gt; — twice, and no dependency appeared (see &lt;strong&gt;Errors you may hit #7&lt;/strong&gt;). The connection string itself was never the problem: the companion console app prints the server version and the demo rows with the same string, and Methods 1 and 2 connect with it too. If the wizard stops on your machine, store the string yourself (Error #7 shows how) and carry on.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The same dialog reaches on-premises servers and Azure SQL Database (that path needs the Azure development workload and an Azure account, and since VS 2022 17.12 it uses Microsoft Entra authentication — Visual Studio does &lt;strong&gt;not&lt;/strong&gt; create the Entra admin user on the database for you, so if none exists, sign-in fails there, not in VS).&lt;/p&gt;

&lt;h2&gt;
  
  
  Visual Studio or SSMS — which do I open?
&lt;/h2&gt;

&lt;p&gt;Not rivals: Microsoft ships both, on separate cadences, for different jobs.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;The job&lt;/th&gt;
&lt;th&gt;Open&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Building the app that uses the database&lt;/td&gt;
&lt;td&gt;Visual Studio&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Browsing and querying while you code&lt;/td&gt;
&lt;td&gt;SQL Server Object Explorer&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Wiring a database into a project&lt;/td&gt;
&lt;td&gt;Connected Services&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Administering the server itself — backups, jobs, logins, configuration&lt;/td&gt;
&lt;td&gt;SSMS&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;SSMS administers the &lt;em&gt;server&lt;/em&gt;, whether or not any application exists; Visual Studio's tools live next to your code and its connections become part of your project. You will end up using both — that is the intended workflow. (Thursday's post goes deeper on the SSMS side: backing up and restoring this same database.)&lt;/p&gt;

&lt;h2&gt;
  
  
  Your connection string, decoded
&lt;/h2&gt;

&lt;p&gt;Everything above eventually produces one line of text. The LocalDB version, keyword by keyword:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight conf"&gt;&lt;code&gt;&lt;span class="n"&gt;Server&lt;/span&gt;=(&lt;span class="n"&gt;localdb&lt;/span&gt;)\&lt;span class="n"&gt;MSSQLLocalDB&lt;/span&gt;;&lt;span class="n"&gt;Database&lt;/span&gt;=&lt;span class="n"&gt;DemoDb&lt;/span&gt;;&lt;span class="n"&gt;Integrated&lt;/span&gt; &lt;span class="n"&gt;Security&lt;/span&gt;=&lt;span class="n"&gt;true&lt;/span&gt;;&lt;span class="n"&gt;Encrypt&lt;/span&gt;=&lt;span class="n"&gt;true&lt;/span&gt;;&lt;span class="n"&gt;TrustServerCertificate&lt;/span&gt;=&lt;span class="n"&gt;true&lt;/span&gt;;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Server&lt;/strong&gt; (Data Source) — &lt;code&gt;(localdb)\MSSQLLocalDB&lt;/code&gt; for LocalDB; &lt;code&gt;HOSTNAME&lt;/code&gt; for a default instance; &lt;code&gt;HOSTNAME\INSTANCE&lt;/code&gt; for a named one (the shape for a hosted or on-premises server too); &lt;code&gt;HOSTNAME,1433&lt;/code&gt; pins the TCP port.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Database&lt;/strong&gt; (Initial Catalog) — the database you land in.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Integrated Security=true&lt;/strong&gt; — Windows Authentication: no password in the string, and the recommended pattern for development. SQL Authentication uses &lt;strong&gt;User Id&lt;/strong&gt; + &lt;strong&gt;Password&lt;/strong&gt; instead — and then the string &lt;em&gt;is&lt;/em&gt; a secret: user secrets or an environment variable, never source control.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Encrypt=true&lt;/strong&gt; — on by default in modern tooling (error #1 below). Non-negotiable on any network you do not own.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TrustServerCertificate=true&lt;/strong&gt; — Encrypt's local-dev companion: accept the dev instance's self-signed certificate. Correct at your desk; in production the real fix is a properly trusted certificate, not this switch.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Coming from Python/FastAPI?&lt;/strong&gt; Same anatomy, ODBC spelling — pyodbc with Microsoft ODBC Driver 18 for SQL Server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DRIVER={ODBC Driver 18 for SQL Server};SERVER=(localdb)\MSSQLLocalDB;DATABASE=DemoDb;Trusted_Connection=yes;Encrypt=yes;TrustServerCertificate=yes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you deployed the FastAPI app from an earlier tutorial in this series to Azure App Service, this string is exactly what its configuration needs next.&lt;/p&gt;

&lt;h2&gt;
  
  
  Errors you may hit
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. "The certificate chain was issued by an authority that is not trusted"
&lt;/h3&gt;

&lt;p&gt;The error that defines connecting to SQL Server in 2026. Since Visual Studio 17.8 the data tools enable &lt;strong&gt;Encrypt by default&lt;/strong&gt; — modern Microsoft.Data.SqlClient does the same — so your connection demands a TLS certificate from a trusted authority. A local dev instance presents a self-signed one, and the connection dies. It is not your server name, not your password, not a broken install.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;At your desk:&lt;/strong&gt; add &lt;code&gt;TrustServerCertificate=true&lt;/code&gt; (or tick the equivalent in the Connect dialog) and reconnect. Microsoft's own LocalDB examples use exactly this pair.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;In production:&lt;/strong&gt; install a certificate from a trusted authority. The trust-anything switch is a development tool, full stop.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. "A network-related or instance-specific error occurred…" (error 40)
&lt;/h3&gt;

&lt;p&gt;Server not found or unreachable. Causes, in order: the instance name is misspelled (the &lt;code&gt;\INSTANCE&lt;/code&gt; half especially), or the Database Engine service is stopped. Open &lt;strong&gt;Services&lt;/strong&gt;, confirm the instance is running, re-check the spelling against Step 2.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. "Login failed for user" (error 18456)
&lt;/h3&gt;

&lt;p&gt;Authentication reached the server and was refused — classically, a SQL login (&lt;code&gt;sa&lt;/code&gt;, or one you created) against a server installed in &lt;strong&gt;Windows authentication mode only&lt;/strong&gt;: Mixed Mode was never enabled at setup, or the login does not exist. Fix the Step 2 choice, or create the login under SSMS → Security.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. "(localdb) … server was not found"
&lt;/h3&gt;

&lt;p&gt;LocalDB itself is missing. The &lt;strong&gt;Data storage and processing&lt;/strong&gt; workload (or the SQL Server Express LocalDB individual component) installs it — a NuGet package does not. Visual Studio Installer → Modify → add it, then confirm with &lt;code&gt;sqllocaldb info&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. A named instance is unreachable from another machine
&lt;/h3&gt;

&lt;p&gt;Three suspects: &lt;strong&gt;TCP/IP disabled&lt;/strong&gt; in SQL Server Configuration Manager, the &lt;strong&gt;SQL Browser&lt;/strong&gt; service stopped, or the &lt;strong&gt;firewall&lt;/strong&gt; closed on port 1433. Enable, start, open, restart the instance, retest.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Python: "Data source name not found and no default driver specified"
&lt;/h3&gt;

&lt;p&gt;pyodbc cannot find the driver your string names. Install &lt;strong&gt;Microsoft ODBC Driver 18 for SQL Server&lt;/strong&gt;, then copy its name into &lt;code&gt;DRIVER={...}&lt;/code&gt; character for character — the braces and exact spacing are part of the name.&lt;/p&gt;

&lt;h3&gt;
  
  
  7. Connected Services: "Failed to configure Secrets store"
&lt;/h3&gt;

&lt;p&gt;Method 3's wizard can fail at its last step: the progress dialog ends with &lt;strong&gt;"Failed to configure Secrets store"&lt;/strong&gt; and "Failed to configure dependency SQL Server Database", and no dependency appears under &lt;strong&gt;Service Dependencies&lt;/strong&gt;. This is not hypothetical — it happened on this tutorial's own capture machine (Visual Studio Community 2022 17.14.44, November 3, 2026), twice in a row, and it persisted after running &lt;code&gt;dotnet user-secrets init&lt;/code&gt; in the project and restarting Visual Studio, the two fixes most often suggested for it.&lt;/p&gt;

&lt;p&gt;The important part: &lt;strong&gt;the failure is in the wizard's secrets-store step, not in your connection.&lt;/strong&gt; The connection string itself is unaffected — the exact same string connects fine through Server Explorer (Method 1), SQL Server Object Explorer (Method 2), and the companion console app, which is how this tutorial's demo was verified end to end. If you hit it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Do not debug your server, your login or your string — test the same string in Method 1 first; if it connects there, the database side is proven.&lt;/li&gt;
&lt;li&gt;Store the string yourself instead: add it to your user secrets (&lt;code&gt;dotnet user-secrets set "ConnectionStrings:DatabaseConnection" "..."&lt;/code&gt;) or an environment variable, and let your code read it from configuration — the pattern the "Get the code" section uses.&lt;/li&gt;
&lt;li&gt;Treat the Connected Services dependency as a convenience that may need a Visual Studio repair or update on the affected install, not as a requirement — nothing in your project depends on the wizard having succeeded.
## Practice exercise&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Try it yourself (10 minutes, code in the description):&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Run SqlConnectCheck against LocalDB — it prints your server version and three demo rows.&lt;/li&gt;
&lt;li&gt;In SQL Server Object Explorer, run a New Query against the same instance: &lt;code&gt;CREATE DATABASE PracticeDb;&lt;/code&gt; — then change ONE word in the connection string (the database name) and re-run. PracticeDb starts empty, so watch what the checker does: it creates the DemoCustomers table inside it, seeds the same three rows, prints them back, and ends with the same success line.&lt;/li&gt;
&lt;li&gt;Now break it on purpose: mistype the instance name, re-run, and read the error like a detective — which of the post's six errors is it?
Reply with the @&lt;a class="mentioned-user" href="https://dev.to/version"&gt;@version&lt;/a&gt; line your run printed — I read every one.&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Do I need SSMS if I have Visual Studio?&lt;/strong&gt;&lt;br&gt;
No — everything here works without it. Install SSMS when the job becomes administering the server itself: backups, jobs, logins, configuration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is SQL Server free for this?&lt;/strong&gt;&lt;br&gt;
Yes, for development and testing: the Developer editions and LocalDB cost nothing and need no key. Developer editions are &lt;strong&gt;not&lt;/strong&gt; licensed for production — Express is the free edition that is.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Does this work on Visual Studio 2026? VS Code?&lt;/strong&gt;&lt;br&gt;
2026: yes — same three tools, same clicks. VS Code is a different editor with its own SQL extension; a different path, not covered here.&lt;/p&gt;

&lt;h2&gt;
  
  
  Get the code
&lt;/h2&gt;

&lt;p&gt;The companion folder has the C# console checker (&lt;code&gt;SqlConnectCheck&lt;/code&gt;, Microsoft.Data.SqlClient 6.1.7 LTS, connection string from an environment variable), the Python/pyodbc version, &lt;code&gt;setup.sql&lt;/code&gt; exactly as run above, and a README with the six errors in miniature:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/sajjad037/visual-studio-learn-code/tree/main/topic-07-connect-sql-server-vs" rel="noopener noreferrer"&gt;https://github.com/sajjad037/visual-studio-learn-code/tree/main/topic-07-connect-sql-server-vs&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources — the official Microsoft Learn pages behind this post
&lt;/h2&gt;

&lt;p&gt;Every version pin and procedure above traces to Microsoft Learn (accessed November 3, 2026):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Visual Studio 2022 release notes (17.14.44): &lt;a href="https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-notes" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-notes&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;SSMS 22 release notes (22.11.3): &lt;a href="https://learn.microsoft.com/en-us/ssms/release-notes-22" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/ssms/release-notes-22&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Microsoft.Data.SqlClient support lifecycle (6.1.7 LTS, supported to August 14, 2028): &lt;a href="https://learn.microsoft.com/en-us/sql/connect/ado-net/sqlclient-driver-support-lifecycle?view=sql-server-ver16" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/sql/connect/ado-net/sqlclient-driver-support-lifecycle?view=sql-server-ver16&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Editions and supported features of SQL Server 2025 (the Enterprise/Standard Developer split): &lt;a href="https://learn.microsoft.com/en-us/sql/sql-server/editions-and-components-of-sql-server-2025?view=sql-server-ver17" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/sql/sql-server/editions-and-components-of-sql-server-2025?view=sql-server-ver17&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;SQL Server downloads (the free Developer editions): &lt;a href="https://www.microsoft.com/en-us/sql-server/sql-server-downloads" rel="noopener noreferrer"&gt;https://www.microsoft.com/en-us/sql-server/sql-server-downloads&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Hardware and software requirements for installing SQL Server 2025: &lt;a href="https://learn.microsoft.com/en-us/sql/sql-server/install/hardware-and-software-requirements-for-installing-sql-server-2025?view=sql-server-ver17" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/sql/sql-server/install/hardware-and-software-requirements-for-installing-sql-server-2025?view=sql-server-ver17&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;SQL Server Express LocalDB (the automatic MSSQLLocalDB instance, and Microsoft's own LocalDB connection-string example): &lt;a href="https://learn.microsoft.com/en-us/sql/connect/ado-net/sql/sqlclient-support-localdb?view=sql-server-ver17" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/sql/connect/ado-net/sql/sqlclient-support-localdb?view=sql-server-ver17&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Disclosure: Visual Studio Learn is reader-supported. Some links may be affiliate links, which means the channel may earn a small commission at no extra cost to you. Only tools actually used in the tutorials are ever linked, and affiliate relationships never change a verdict.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>sqlserver</category>
      <category>visualstudio</category>
      <category>dotnet</category>
      <category>database</category>
    </item>
  </channel>
</rss>
