How to connect to SQL Server database using windows authentication remotely? - c#

I have a simple question, I was granted to a SQL Server database using windows authentication on my local machine, I need to know how to use this access on hosting server as well.
For example I am in the middle of writing some C# code that pulls data from this database, I can run this code on my local machine with my windows authentication no problem, but I can't run it on expected hosting server because that server obviously can't connect to that database.
I was just wondering how can I use windows authentication access remotely?
Thanks

Windows authentication must be enabled on the remote server to do this. This can be enabled in server properties > Security and by selecting SQL Sever and Windows Aucthentication radio button. Providing your windows credentials are added to the server then you should be able to login.
On your SSMS right click the database name select properties and select Security from the left hand menu and there you should see the "SQL Sever and Windows Aucthentication" option.
Obviously if your database is not on the same domain then this might not work.

Related

how to simulate log on to a server programatically to use windows authentication

I want to connect to the SQL SERVER and Analysing Server that are using windows authentication. There is no domain in the system so I want to do it by programatically simulating logging on the server with the login and password of the administrator of the server
You need the Net use command to log onto a remote server.
Try this:
NET USE \\DBSERVER /USER:DOMAIN\USERNAME
You will be prompted for your password. This establishes a NetBIOS session with the database server. You should be able to see the shared folders and shared printers on the database server once you have done that.
Once that is successful, you should be able to specify "Integrated Authentication" to connect to the server.
To do this programmatically from C#, use the NetUseAdd function.

SQL Login and access

I am having trouble with SQL.
I installed a fresh version of SQL 2012,
On the creation part I assign a user to be Kleber-Pc, accessed couple times fine.
However when I tried to access it from my asp.net mvc application using windows credentials, the SQL rejected the connection, so I tried to load SQL and its not allowing me to connected it.
The first image below show the login box
The image below show what it results when clicked on connect.
So my questions are:
How can I access SQL?
How can I set up user/password that I can use in my application (instead use windows authentication)?
Obs.:
I didn't create a user account or password for SQL that I remember; I am using Visual Studio 2012 on windows 8 machine.
I searched online and could not find anything related, I am not expert on SQL, so any help will be appreciated.
Thanks.
Option 1 - Mixed Authentication Mode
SQL Server : Step by step installation guide for SQL Server 2012
Video Tutorial
If you are trying to connect using SQL Server Authentication, verify that SQL Server is configured in Mixed Authentication Mode and verify that SQL Server login exists and that you have spelled it properly.
If you are trying to connect using Windows Authentication, verify that you are properly logged into the correct domain.
It’s probably because UAC. Try right clicking and running as administrator and seeing if it goes away.
OR
SQL Authentication not enabled: If you use SQL Login for the first time on SQL Server instance than very often error 18456 occurs because Windows Authentication (only) is set in Server properties (security section).
To Access Server Properties, Open SSMS, go to Object Explorer pane (use view if you can't see it). Use the connect button to connect to database engine for your server. Once connected you will see it in object explorer. Right click server and click properties. Server Properties window will appear.
microsoft sql server error 18456 login failed for user server properties
See below screenshot that might be causing SQL login to fail
18456 windows authentication
You should set Server Authentication to SQL Server Windows Authentication Mode (see below). Once you select SQL Server Authentication you have to restart the server.
18456 sql authentication
Restart required: You have to restart the service when you change server authentication but bear in mind if someone hasn't restart the service this might be the reason why you get 18456. Remember service restart should be carefully planned on production servers as it will clear certain information (cache) and may impact performance of the server.
NOTE: I recently tried to restart service using SSMS 2012 on Windows 7 and it didn't work.... actually the message below was hidden behind SSMS window and I just did not see it so ensure you get this message when you decide to restart the service.
18456 restart required
Invalid userID: SQL Server is not able to find the specified UserID on the server you are trying to get. The most common cause is that this userID hasn’t been granted access on the server but this could be also a simple typo or you accidentally are trying to connect to different server (Typical if you use more than one server)
Invalid password: Wrong password or just a typo. Remember that this username can have different passwords on different servers.
less common errors: The userID might be disabled on the server. Windows login was provided for SQL Authentication (change to Windows Authentication. If you use SSMS you might have to run as different user to use this option). Password might have expired and probably several other reasons…
18456 state 1 explanations: Usually Microsoft SQL Server will give you error state 1 which actually does not mean anything apart from that you have 18456 error. State 1 is used to hide actual state in order to protect the system, which to me makes sense. Below is a list with all different states and for more information about retrieving accurate states visit Understanding "login failed" (Error 18456) error messages in SQL Server 2005
ERROR STATE ERROR DESCRIPTION
------------------------------------------------------------------------------
2 and 5 Invalid userid
6 Attempt to use a Windows login name with SQL Authentication
7 Login disabled and password mismatch
8 Password mismatch
9 Invalid password
11 and 12 Valid login but server access failure
13 SQL Server service paused
18 Change password required
Source
Video Tutorial
When you installed SQL did you set kleber-pc as a SQL user? If not the user will be 'sa' you will have been prompted to enter an sa password.
If you can't remember the password you'll most likely have to re-install the instance.
Once you are logged in (with an appropriate account) you will be able to add/edit user accounts as you wish.

Test transition from Windows Authentication to SQL Server authentication

I have a windows forms application which connects to an SQL Server 2008 R2 database using variously SMO, databinding, and ODBC connections.
Currently it uses entirely Windows authentication, but a client has requested that we also allow SQL Server logins.
Given the only Windows login I have, and can have, is my own, what can I do to test whether my code is actually using the SQL Server login and not simply connecting using my own Windows login?
Alternatively, what can I do to refine this question so it makes sense?
Thanks
Your question is too general but here are some steps you should take.
Create new sql login and only give necessary permissions to this user
Update all connection strings in your application. If these are not consolidated in one config file now is the good time to do this. You can even consider creating a separate class that will handle this.
Add login form to your app that will be shown at the application startup so that user can enter credentials
Best way to test this is to simply disable your windows user in SQL Server and see if application is still running.

Pass Windows Identity through Client Server framework to SQL Server

I have a corporate client server application. It passes majority of the work from the client application (Windows 7) to the server application (Server 2008 R2), and when it comes to running a SQL query (SQL Server 2008), it is handled by the server - which registers the user as the server.
We then have a table in our database which is locked down using Active Directory.
Our client and server are written in .Net 4.0. I'm Using WCF (net.tcp).
How would I pass the logged in user security token from our Windows 7 client, to our server in order for the server to turn around and use it to connect to the SQL server to run a couple of quick queries.
Any thoughts, or ideas, would be greatly appreciated! Thanks.
You might want to create a service account for SQL server access.
You can impersonate/change identity in your windows application using the service account before making a call to database. so while database call is being executed it will run under impersonated identity(service account). For impersonation in windows application see this MSDN Article
What you are talking about is the double hop scenario. Check out this SO question regarding how to set up double hop possibilities.

windows app, using SQL Server, need to it work on PCs on a different domain

Part of our company has moved to another area and they are being set up as a separate domain. The users can VPN in to our domain to run the app, but when they try to access the database it fails, because SQL Server is set for Windows Authentication, and they are on a different domain. It is a Windows C# app, we are using SQL Server 2005 Express, I could set this for mixed mode Authentication but I'm still not sure how to proceed from there.
You have to download and install SQL Server 2005 Management Express. Once installed, open it from a pc under your domain, and go to Security->Users->SA user->Properties.
Set a password for it and set its state to "Actvated". You can use its account info to login from wichever domain you have to.
If you want, setup a new user instead of use SA: Sa is very powerful user, and you can mitigate security issue allowing only normal users to access from extern.
To use your new user info, you have to edit your connection string, changing
Integrated Security=True
to
Integrated Security=False;User=YourUserHere;Password=YourPasswordHere
You don't have to use SQL Server authentication for this. You can connect via windows authentication by starting up management studio as follows (obviously the path might need adjusting your end)
runas /user:OTHERDOMAIN\OTHERUSERNAME /netonly
"C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\SqlWb.exe"

Categories