Login Failed for User (Microsoft SQL Server, Error: 18456 - sql-server-2008

I have SQL Server 2008 running on my local machine. I have removed myself from Database --> Sercurity. Now I cannot login and I am getting following error
Login Failed for User (Microsoft SQL Server, Error: 18456)
My Login is auttenticating from Active Directory

If you removed or disabled your login to the dmbs and have no other Logins to repair the situation, this Tip from a Microsoft Blog may apply:
Here are the steps you will need to perform:
Start the SQL Server instance using single user mode (or minimal configuration which will also put SQL Server in single user mode)
From the command prompt type: SQLServr.Exe –m (or SQLServr.exe –f)
Note: If the Binn folder is not in your environmental path, you’ll
need to navigate to the Binn folder.
(Usually the Binn folder is located at: C:\Program Files\Microsoft SQL
Server\MSSQL10.MSSQLSERVER\MSSQL\Binn)
Once SQL Server service has been started in single user mode or with minimal configuration, you can now use the SQLCMD command from
command prompt to connect to SQL Server and perform the following
operations to add yourself back as an Admin on SQL Server instance.
SQLCMD –S
You will now be logged in to SQL Server as an Admin.
Once you are logged into the SQL Server using SQLCMD, issue the following commands to create a new account or add an existing login to
SYSADMIN server role.
To create a new login and add that login to SYSADMIN server role:
1> CREATE LOGIN ‘’ with PASSWORD=’’
2> go
1> SP_ADDSRVROLEMEMBER '','SYSADMIN'
2>go
To add an existing login to SYSADMIN server role, execute the
following:
1> SP_ADDSRVROLEMEMBER ‘’,’SYSADMIN’
The above operation will take care of granting SYSADMIN privileges to
an existing login or to a new login.
Once the above steps are successfully performed, the next step is to stop and start SQL Server services using regular startup options.
(This time you will not need –f or –m)

Related

Visual Studio Code mssql extention: SQL Server (mssql) - Unable to connect to server

I'm trying for the first time to get my project to run in Visual Studio Code. This includes a MySQL database. So I've installed the SQL Server (mssql) extension version 1.7.1. I follow the instructions here: https://learn.microsoft.com/en-us/sql/visual-studio-code/sql-server-develop-use-vscode?view=sql-server-ver15
I get to the section "Connect to SQL Server" and enter:
servername: localhost
db name: c3
Authentication type: Integrated
At the end of the section it should connect with the server but instead I get two errors:
mssql: Error "Unable to connect using the connection information
provided. Retry profile creation?"
mssql: Error 2: A network-related or instance-specific error occurred
while establishing a connection to SQL Server. The server was not
found or was not accessible. Verify that the instance name is correct
and that SQL Server is configured to allow remote connections.
(provider: Named Pipes Provider, error: 40 - Could not open a
connection to SQL Server)
Does anyone see what is going wrong here?
I've re-installed the extension but with the same result.
A MySQL db and Microsoft SQL Server db are two different things.
It seems that there's no SQL Server installed? You might install the free SQL Server Express Version, create the database in there and then connect from Visual Studio Code.
You have to install the database server yourself as VS Code is just a client. You might also use somekind of hosted offers (many webhosters offer a mysql server with self service installation, or use a cloud based database server). Yout can also use a local database (e.g. SqlLite) which is file based and doesn't need a special installation.
You should do the following
install SQL server in your machine and create Database here
Create a login and a database user here
If you are Using VS code install SQL Server (mssql) open new
connection, follow the prompts to specify the properties for the new
connection profile
If you want to login to your server to make sure of your data
sqlcmd -S localhost -U SA -P '<YourPassword>'

SQL server ODBC connection for Active Directory user who doesn't log in to the windows

Do you think it is possible to create a SQL server ODBC Connection for an active directory user who doesn't log in into the windows.
Ideally this type of users will be used in the batch process. So, Another person logs in and creates a batch process and runs it with another user.
Note: I dont want to create a SQL server authentication. Instead would like to use active directory.
Thanks.
You can't save alternate windows authentication credentials into an ODBC connection for SQL Server. You can only save credentials into the ODBC setting if you use SQL Server authentication.
There are other options though.
You can create a windows authentication ODBC connection to SQL server even if the account you create the connection with doesn't have database access. You just have to untick the "Connect to SQL Server to obtain default settings for the additional configuration options" and you can't use the "Test connection" feature. You just have to create the connection on faith.
With that connection, it will only work if your batch process or application is running as a different account to the logged-in user. Services that run as system accounts do this sort of thing. If you create an application that can be run as a service then you can change the account it runs under.
You can also run as another account manually. Using explorer you can [shift] + right-click on an application and choose "Run As different user" and then enter the other account credentials. Then when the process or application uses the ODBC connection, it will be the correct credentials and work.
There's also "ShellRunAs" https://technet.microsoft.com/en-us/sysinternals/shellrunas.aspx

SQL mangement user error

When i am creating users in SQL management studio i create them under the server name and then i create them under the database but when i try to log on using the user name and password i cant. getting erro saying
> TITLE: Connect to Server
Cannot connect to LAPTOP-RED\SQLEXPRESS.
ADDITIONAL INFORMATION:
A connection was successfully established with the server, but then an error occurred during the login process. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.) (Microsoft SQL Server, Error: 233)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=233&LinkId=20476
BUTTONS:
OK
And the suggested solution from the help link is:
User Action
Use the SQL Server Surface Area Configuration tool to allow SQL Server
to accept remote connections. For more information about the SQL
Server Surface Area Configuration Tool, see Surface Area Configuration
for Services and Connections.
Which is what you have to do. By default the SQL Express Server isn't configured to allow remote connections.
hi I faced same issue in MicroSoft sql server 2008.
this error occurs while user limit exceeded, as you have set max connection to 1 and if someone is already logged in (or using any webpage which access your server) then it will not allow anyone to access directly or indirectly. to solve this issue simply follow following steps:
stop all web services.
open services.msc using RUN and ****restart sql server** and do not start any service which uses your sql server, so that you will be able to log in using sql server management studio.
now open sql server management studio and click on New Query button.
It will ask for user name and password use your login name and password.
run these scripts one by one sp_configure 'user connections', 0
go
6.reconfigure with override
after this restart your sql server it will show a confirmation message click on OK.
Bingo
It works. please don't forgot to vote ;-)

Cannot connect to database,.Login failed for user

Yesterday my database was connected perfectly.
We have installed Windows Server 2008 R2 on our server and the I have added the user to the client PC name SMTECH5 with user jangid
Now my database is not connecting using windows authentication.
only the master database is connecting.
Here's the the error:
Cannot connect to SMTECH5\COLLEGEERP.
Cannot open user default database. Login failed.
Login failed for user 'SMTECH\jangid'. (Microsoft SQL Server, Error: 4064)
If you go to enterprise manager as a different user, go to the security, logins node and select the user - then change the default database to master.
That should sort it.
The reason is because the default database has been removed (look comment on the question).
You have to Open Sql Server Management Studio, connect to the database, then open Security -> Logins-> right click on the account jangid -> Properties: on the bottom of the window you have to change the default database to the available one, or master.
Try this in SQL Server Management Studio.
1: Open 'Connect to Server' popup
2: Select 'Options >>'
3: Change the value in the dropdown 'Connect to database' from <default> to master.

How to make SQL Server find a login matching the name provided?

I have just restored a database backup to my local SQL Server express instance.
In management studio under the server instance node I went to: Security -> Logins -> New login...
Then I filled in a login name, password and chose SQL Server authentication. And at the bottom I selected the newly restored database to be the Default database.
At the User Mapping 'tab' at the left, I mapped the user to the newly restored database and gave it "db_owner" role.
When I try to login the following error is given in the log:
Login failed for user 'username'. Reason: Could not find a login matching the name provided. [CLIENT: ]
How can I make SQL Server find the login matching the name I provided?
Other info:
Named pipes are enabled
TCP/IP is enabled
Remote connections are allowed
Please make sure you have selected "SQL Server Authentication" mode for user you created from
Server > Security > Logins option.
Another possibility, is that you created the SQL Server login using Management Studio, and the option requiring the user to change the password on first login was checked. If you didn't immediately login with Management Studio, and change the password, then the attempt to login from the other machine is not able to pop up a dialog box to change the password and so it fails.
try it by removing user and create again.
This is old but for some one who encounters error for ASP.Net Core 2.2 using EF core and VS Code, I got error
Error Number:18456,State:1,Class:14
Login failed for user 'sa:password=MyPassword'.
I looked logs from SSMS and found error as
Login failed for user 'sa:password=MyPassowrd'. Reason: Could not find a login matching the name provided. [CLIENT: MyIp]
After searching here and there i found that I have to add Persist Security Info=False in connection string, so my connection string became like
"Default":"Persist Security Info=False;User ID=sa;Password=MyPassword;Initial Catalog=MyDb;Server=MyServerIp"
I found this format from Microsoft Docs. After that it worked fine.
persist security info=false is default. I didnot found any reason why my connection string without it was not working. From here