Test SQL Server connection for an Active Directory account - sql-server

I have a SQL Server login created (Windows Authentication) and SQL Server user linked to the login.
I want to test the connection to this SQL Server from another server on the network for this particular Active Directory account (different than my AD account). I do not have a SSMS(SQL Server Management Studio) installed on the server I want to test the connection from.
How can I do that?

Figured it out. Here is how I tested it:
Create a Microsoft Data Link file (.udl) anywhere on the client machine. Just create a new test.txt file and rename it to test.udl
Opening the properties dialogue of .udl file lets you test the connection to a SQL Server. My problem was that the connection to the SQL Server needs to be tested for an AD account different than mine. To do this, run the command prompt as that user on the client machine:
In command prompt, navigate to the folder that contains test.udl file and type the name of the file in the prompt.
This will open the properties of the .udl file. Go to Connection tab and provide the SQL server name:
Select "Use Windows NT Integrated security" in section #2:
When you click on the database drop-down in section #3 and you are able to see the list of databases, that means that the login worked for the user. If you wish you can select a database from the list and click "Test Connection" button to test a specific database connection.

Related

Accessing SQL Server remotely using Windows Authentication

I have setup SQLExpress on a Windows 10 PC and trying to access it via another PC.
I also configured my setup using this guide.
I was able to connect using SQL Server Authentication.
However, when I tried connecting using Windows Authentication, I received the following message:
The login is from an untrusted domain and cannot be used with integrated authentication.
Is there a step I might have missed?
You may need to launch your SSMS under a different set of credentials (runas) in order for it to connect via windows authentication. One way to do this is to create a simple batch file (or shortcut) to do so.
Create a batch file on your desktop and name it something like:
AltSsms.bat
Add the following line to the AltSsms.bat file:
runas.exe /netonly /user:{domain}\{username} "C:\Program Files (x86)\Microsoft SQL Server Management Studio 18\Common7\IDE\Ssms.exe"
Be sure to replace {domain} and {username} with the actual values expected by the remote computer, and provide the full path to your local SSMS installation. I've provided my SSMS path for reference.
Save the updates to the batch file and then double-click it to open it. You should be prompted to enter the password for the {domain}\{username} you specified in the batch file.
Once SSMS loads (and assuming you've entered proper credentials), attempt to connect to the SQL Server instance with Windows Authentication. I've had to do this with several SSIS setups.

Cannot open database "DatabaseName" requested by the login. The Login failed. Login failed for user

Here is the scenario.I'm creating a desktop application with VB.NET (Windows Forms), and using SQL Server 2008 R2 for its database.
I have two computers (PC1 and PC2) and I want to connect PC2 to PC1.
PC 1 has the SQL Server database. What I do is I just copied .exe application in
the debug folder of my vb project and create a notepad for its connection and put them into one folder and transferred it to PC2.
When I run my application to other PC, I get an error
Unhandled exception has occurred in your application. If you click
Continue, the application will ignore this error and attempt to
continue, If you click quit, The application will close immediately.
Cannot open database "DatabaseName" requested by the login. The Login
failed. Login failed for user
My code inside the notepad
Data Source=.;Initial Catalog=DBSAS;Integrated Security=True
What I have done so far is to enable remote connection of SQL Server 2008 R2.
Can someone please give me an advice about this? I am really confused. Thanks
Hi please find sql server instance name at PC 1 using below command
OSQL -L
replace . to the instance name at you connection string.
Specify Data Source= "sql server instance name " in the connection string.
more detail are posted on below link.
How can I determine installed SQL Server instances and their versions?.
On the second pc create a txt file on desktop. Something like test.txt. Then rename it to test.udl Universal Data Link. Double click the test.udl. From there you can produce a valid connection string to the SQL Server. After you are done open the udl file with notepad to get the connection string. Hope this helps.
Specify Data Source=PC1 in the connection string. The . indicates a local SQL Server instance running on the same machine as the application. The error suggests SQL Server is installed on PC2 but doesn't contain the desired database.
EDIT:
The error
Cannot open database "DatabaseName" requested by the login
indicates authentication was successful to the SQL Server but the database context could not be set. If DatabaseName in the error message is the same one as the Initial Catalog in the connection string, then either the database does not exist or the user does not have permissions to use it. However, if the DatabaseName in the error message differs from the connection string, the connection string you changed is not the same one that is actually being used by the application.

Local SQL Server database is not connected

I am using Entity Framework version 6.0. I want to connect to a local SQL Server database. I am using the following connection string. But I cannot connect to the database. Please give me the solution.
<add name="dbecommerceEntities"
connectionString="metadata=res://*/Models.dbEcommerceMode.csdl|res://*/Models.dbEcommerceMode.ssdl|res://*/Models.dbEcommerceMode.msl;provider=System.Data.SqlClient;provider connection string="data source=localhost;Integrated Security=False;Initial Catalog=dbecommerce;User ID=qaws;Password=1q2w!A#S;Connect Timeout=30000;Encrypt=False;Packet Size=4096;App=EntityFramework"" />
Check the usual suspects:
data source=localhost : this means, there must be a default, unnamed SQL Server instance on your local computer - is there? Or did you install SQL Server Express in default mode? Then you'd have to use data source=(local)\SQLExpress instead
User ID=qaws;Password=1q2w!A#S : do you have this user ID and this password as a login on your SQL Server instance?
Initial Catalog=dbecommerce;: does that database exist on that SQL Server instance? Is the login from above defined as a user in this database, and has the permissions needed to do work?
my connection string was correct. one of the file was not uploaded to the server. now it is working correctly.
Here is what I do to test connection to database:
Create a .txt file somewhere in your computer.
Rename the file to .udl
Accept the change extension question and double click the file to open.
In your case, in the first tab, select SQL server and in the second tab, fill in the required fields.
Test the connection and if unsuccessful, it will provide you an error.
If successful, close the dialog and open the .udl file with notepad, you can see the connection string in the second line after ";" (the first semicolon)
HTH

create database permission denied in database ‘master'-sql 2008 R2

So I have installed SQL Server 2008 R2 on windows 7 machine.I was able to login using my windows authentication.Now when I try to create a new database it gives me this error saying "CREATE DATABASE permission denied in database ‘master'".I have tried so many links related to this issue but still it is failing.These are the options that I tried:
1) Went to SQL Server Configuration Manager and then changed the parameters in the advanced tab by adding -m.It still did not help me.When I add this parameter and try to login again using windows authentication it gives me a message saying "Only one administrator can login as it is in single user mode".
2) While Installation I am sure that I added the current user under sysadmin role. I also made sure that the "Mixed mode authentication" is selected and then gave a password for the user "sa".Now when I try to use that password it says "Failed login for user sa".
3) When I login with windows authentication and then check the login mode by following this:
right click on main instance name-->Properties-->Security,it shows that only windows authentication mode is selected.But I am very much sure that I selected the "Mixed mode authentication".Not sure why it is showing it in this way.
4) I also tried to modify the password for sa but the current user has no permissions.I am not able to perform any operation with this user.
I know there are different links for this issue.But I tried all the options that were mentioned in those links but still it is giving me a problem.I have been trying to resolve this issue from a very long time.Could anyone suggest what I am missing here.
Solved! I had the same problem. I figured it out based on info from the article and the comments from the first commentor in this link.
I'll copy the author's steps with the necessary modifications in bold:
Open the Configuration Manager tool from the "SQL Server 2005| Configuration" menu
Stop the SQL Server Instance you need to recover (both SQL Server AND SQL Server Agent. Once in single user mode, if not stoped, the agent will tie up the connection, preventing you from using it with sqlcmd.exe).
In SQL Configuration Manager, click on SQL Server Services on the left, then right click on SQL Server on the right, navigate to the “Advanced” tab (or "Startup Parameters for more recent versions of SQL), and in the Properties text box add “–m” to the end of the list in the “Startup parameters” option.
Click the “OK” button and restart the SQL Server Instance (just SQL Server. Do not restart the SQL Server Agent just yet.) NOTE: make sure there is no space between “;” and “-m”, the registry
parameter parser is sensitive to such typos. You should see an entry
in the SQL Server ERRORLOG file that says “SQL Server started in
single-user mode.”
After the SQL Server Instance starts in single-user mode, the Windows Administrator account is able to connect to SQL Server using
the sqlcmd utility (it is probably here, or someplace very similar: C:\Program Files\Microsoft SQL Server\110\Tools\Binn\SQLCMD.EXE) using Windows authentication. You can use
Transact-SQL commands such as "sp_addsrvrolemember" to add an existing
login (or a newly created one) to the sysadmin server role. The
following example adds the account "Buck" in the "CONTOSO" domain to
the SQL Server "sysadmin" role: EXEC sp_addsrvrolemember
'CONTOSO\Buck', 'sysadmin'; GO
Restart/Start SQL Server Agent, back in the SQL Server Configuration Manager.

SSIS - how to make a connection string for your database server?

How do i make a connection string for my database server ? I want to know this so that i can save connection strings in a table and then use them later. Note - All my database servers don't need password and username. I login to a remote "mother" server and access the other remote servers in management studio using 'windows authentication'. So, i don't think my connection string needs to have a user name and password.
Assuming this is for SSIS, create a connection manager, then poke around in it's properties - you'll find the connection string. Take a look here for examples:
http://www.connectionstrings.com/
When connecting to an MS SQL database you require to log in using an account. I am assuming that the windows account you use to connect to the remote server is also the account that is used to log into server is the same account that is used to log into the server. So you can set a connection manager using the same window authentication.
To set up a new connection from BIDS open the solution manager window, then one right hand mouse click on 'Connection Managers' and left hand mouse click on 'New Connection Manager'
The 'Add SSIS Connection Manager' window will appear, this example l have selected and OLE DB connection, next click on the 'Add..' button.
The next screen may already have connections defined as the screenshot shows. Press the 'New..' button to add another data connection.
This final screen is where you provide the details of the database you wish to connect to. The combo box titled 'Server name' when you click on the down arrrow, may contain the server\database instance you want to create a connection for. Otherwise you can enter it manually by typing it directly in the the box. The syntax is as follows [database server name][MS Sql server instance name] eg Yoda\LukeDB. Where 'Yoda' is the name of the server and 'LukeDB' is the name of the database instance you want to connect to. In the screenshot the 'Log on to the server' is set to 'Use Windows Authentication'. However this assumes the windows account on you access the remote server with is the same as the machine running the SSIS package. Once you have entered all the details, press 'Test Connection' to check if a connection can be made successfully.
From a security point of view it would be recommended to set up a SQL account on the database instance which the SSIS package is run against. Then configure that SQL account just the permissions it requires to run the SSIS package.

Resources