Как подключиться к database sql
Перейти к содержимому

Как подключиться к database sql

  • автор:

Connect to SQL Server Using Management Studio

In this tutorial, let us learn how to connect to SQL Server Using SQL Server Management Studio (SSMS). Using the SQL Server Management Studio is a simple and easy way to connect to the SQL Server Instance.

If you have not installed the SQL Server, then you must visit how to install SQL Server & How to install SQL Server Management Studio tutorials

Table of Contents

Starting SSMS

Start SQL Server Management Studio. You can find it from

Program files -> Microsoft SQL Server Tools 18 -> Microsoft SQL Server Management Studio

SQL Server Management Studio in Program Files

The first time you run SSMS, the Connect to Server window opens.

If it doesn’t open, you can open it manually by selecting Object Explorer > Connect > Database Engine. If Object Explorer is not opened, you can open it from the Menu -> View -> Object Explorer

Object Explorer Menu

Object Explorer

Connect to Server

The Connect to Server window appears as shown below

Server Type: Choose Database Engine to connect to SQL Server database Server.

Server Name: Server Instance Name. Use your computer name if you want to connect to default Instance. Else enter the name as <compuetName>\<InstanceName>

The instance name is the name you have given when you were installing the SQL Server under Instance Configuration.

Authentication: There are two authentication modes. One is Windows & Another one is SQL Server authentication mode. If you choose windows, then the current logged in user is automatically picked by the system.

SQL Server Authentication works only if you have selected the Mixed Mode authentication when you were installing the SQL Server. We set up this while configuring the database engine.

User Name: This is enabled when you choose SQL Server Authentication Mode. If you are connecting to the newly installed SQL Server then the only user you have is sa.

Password: Enter the sa password

Connect to SQL Server Using Windows Authentication

Connect to SQL Server Using SQL Server Authentication

Click on Connect to Connect to the Server

Object Explorer

The SSMS connects to the SQL Server Instance. On Successful connection, you will see the object explorer as shown in the image below.

SQL SERVER Connected Via SQL Server Management Studio

Under the Server Name, you will see various nodes like database, security, management listed. Expand the Databases node to see the list of databases available. In a newly installed server, you won’t see any database except for the System databases.

Summary

We use SSMS to connect to the database. SSMS Provides the GUI tools to explore & Manage a database instance.

How to connect to your local MSSQL server using SSMS?

This post was most recently updated on January 13th, 2023.

Every now and then you run into a situation, where you really need to run some SQL against your local development database. That database, at least in my case, is hosted on your local SQL Server Express.

Connecting to a local SQL Server should be a walk in a park, right? Eh, well…

While using a connection string to connect to said DB is easy, you can’t do that with the SQL Server Management Studio. I wish you could, but hey – it is what it is.

There’s a couple of ways to connect, though! Let’s start with the easy one, that doesn’t always work:

How to connect to your local database with SQL Server Management Studio?

Table of Contents

Connecting to the local instance might work by using the name of the instance. While I’m not sure what’s the reason it hasn’t worked for me (I wonder if the instance names differs based on what you’re installing the SQL Server or SQL Express with. ), maybe it works for you.

Essentially, just paste this into the connection window:

Or like shown below:

How to log in to local SQL Server database using SQL Server Management Studio.

How to log in to local SQL Server database using SQL Server Management Studio.

Workaround: Use Named Pipes instead

If it doesn’t work – well, there’s a workaround, although it’s a bit laborious. It in fact requires you to know the instance name pipe – a weird, nonsensical URI-looking piece of textual vomit you simply can’t guess. And then, most of the time, you can just use your local user account to log in.

The workaround has quite a few steps, and finally comes down to this beautiful screen below:

How to log in to local SQL Server using named pipes.

How to log in to local SQL Server using named pipes.

But how do you figure out the right Server name? Check out the steps below!

Time needed: 10 minutes.

    Try using (localdb)\MSSqlLocalDb first

It won’t hurt testing “(localdb)\MSSqlLocalDb” for Server name – just to see if it works.

The location is something like this under your SQL Server’s installation path -> Tools -> Binn.

Easy enough – run this in your console:
SqlLocalDB.exe

SqlLocalDB.exe output in console.

The tool should output something like this:

Next, let’s run the command with parameter “info”.
> SqlLocalDB info
MSSQLLocalDB
ProjectsV13

Now we’ll get to actually run the command for our instance. This’ll look somewhat like below:
SqlLocalDB info [instancename]

You’ll want to get this server up and running. That’s easy – just run the command below:
SqlLocalDB start MSSQLLocalDB

The output might be something like below:

Or in text form:
SqlLocalDB info MSSQLLocalDB
Name: MSSQLLocalDB
Version: 13.1.4001.0
Shared name:
Owner: [username]
Auto-create: Yes
State: Running
Last start time: 2020-08-12 1:22:49 PM
Instance pipe name: np:.\pipe\LOCALDB#A4E758FA\tsql\query

Pay very close attention to the state – it should now be “running” – and note “Instance pipe name“!

And boom! You should be good.

Frequently asked questions

The executable installation file is hosted by Microsoft – they keep changing the shortlink of the actual download, so your best bet is to download it from the Learn/Docs page describing the tool – here: https://learn.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms?view=sql-server-ver16

References and appendices

Updated 13.2.2020: Added mention of the easier method, thanks Mika Berglund.

For further reference, check out these links:

Appendix 1: the output of SqlLocalDB.exe

I’m including the whole default output of SqlLocalDB.exe here, as it won’t fit into the step-by-step instructions above.

mm

Antti Koskela is a proud digital native nomadic millennial full stack developer (is that enough funny buzzwords? That’s definitely enough funny buzzwords!), who works as Solutions Architect for Precio Fishbone, building delightful Digital Workplaces.

He’s been a developer from 2004 (starting with PHP and Java), and he’s been working on .NET projects, Azure, Office 365, SharePoint and a lot of other stuff. He’s also Microsoft MVP for Azure.

How to connect to a local database in SQL Server Management Studio?

I have downloaded the SQL Server Management Studio (SSMS) 2016 to recover a huge .bak file which is an old backup of a database. But first of all I need to connect to a DB Server.

After install, I execute SSMS and it asks me to connect to a DB Server. I don’t have any and I saw that it is possible to create a «local» db by typing only a dot ‘.’ for Server Name and use Windows authentication.

It is not working; how to do it?

5 Answers 5

  1. Open SSMS -> Connect
  2. Server name: (LocalDb)\MSSQLLocalDB ,
  3. Choose Windows Authentication.

For a reference:

enter image description here

Xin's user avatar

You need to download and install SQL LocalDB. It is a special edition of SQL Server that does not allow remote connection and supports windows integrated authentication only. It is a simple one click MSI install so it is easy to deploy.

To download and install SQL Server 2016 Express, go to SQL Server downloads. LocalDB is a feature you select during installation, and is available when you download the media. If you download the media, either choose Express Advanced or the LocalDB package.

The above means that now you have to download and run a small downloader (cca 5 MB), select LocalDB (44 MB) and the Microsoft downloader will download MSI package to the folder you select. Then just run MSI package and LocalDB gets installed.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *