How to set user Windows password in SQL Server - sql

I am using SSMS to interact with a database I have locally on my PC. I also have a software to create reports about data in the database, but first of all I have to connect the software to the SQL Server database.
I'm logging into the database using Windows authentication (credentials WindowsDomain\username) which is my PC name and Windows username. At the beginning I didn't set a password and it connected successfully.
But to connect the software to the database, I have to fill in different fields such as Host Name, Port Number, Database Name, User, Password. I can't leave empty the Password field even if I don't have one, so I need to set a password for my Windows username : OK easy, I just have to set the password account in the Control Panel..
I restart my PC and check if I need to fill the password, now, in SQL Server.. But it still connects without any password, the software does not connect the database with that password, and in SQL Server I can't solve it with a query (alter login on my username), error :
Cannot use parameter PASSWORD for a Windows login.
How can I set a password for this user name ? Or maybe to create a new one with SQL Server authentication or Windows authentication, it's the same for me...

If you are trying to use password with Windows Authenticationthat is not a correct way and also imposible because Windows AuthenticationLogin is different from SQL Login.
In Windows Authentication you don't have a password because Windows tells SQL that I trust this user(who is loged in on this computer) so you can trust him

Related

Cannot access Azure SQL database

I am having trouble accessing my Azure SQL database. I Have whitelisted my ip address(using 'what is my ip' in google to find it) The connection string in the azure portal is -
Driver={SQL Server Native Client
10.0};Server=tcp:nrmuolxpqg.database.windows.net,1433;Database=databasename;Uid=username#nrmuolxpqg;Pwd={your_password_here};Encrypt=yes;Connection
Timeout=30;
What do I put into the Migration Tool, or into visual studio as the connection properties? In particular what to do with the 'tcp' at the starte of the server string?
The fields I need to fill in are:
-Server name (do I need to put tcp or the port number in here? )
-Login
-password - (this is my windows account password right? )
-Database
The only thing you need to change is the username and password. This is something you specified when you created the server. It's not the same as your Windows username and password.
If you forgot the password, you can reset following these instructions, Password reset for Azure database.
EDIT 06/20/2018 - Finding the username
If you forgot your username, you can find it by clicking the Show database connection strings link in the Essentials window.
The ADO.NET connection string will not show the username but any of the other examples will.
Here are a few additional things you can try to resolve connection issues.
Try pinging the server. The server doesn't respond to the request but the name should be resolved to an IP address.
Verify that your client IP address has been added as a firewall rule.
Make sure you are using the correct connection string (in your question you are using the ODBC connection string, you might want to try the ADO.NET one). Also double-check that you use the correct username and password.
To connect from Visual Studio, add a connection from the Server Explorer window using the server name and login info as shown below. Obviously you have to change the server name and login info to match you specifics. I'm connecting to a database called StackDemo in the below screenshot.
If you still can't connect, there might be an issue where your company's or personal firewall is blocking the connection.

Get windows user login name from sql server

My database is configured to use SQL server authentication with login name sa. Now I would like to know what is the user's Windows login user name. SA will be there for everybody. I was able to get the computer IP address and Computer name, but I desperately need the user's Windows login user name. My network is setup using active directory btw.
set #UserComputerIP = CONVERT(varchar(20),CONNECTIONPROPERTY('client_net_address'))
set #UserComputerName = CONVERT(varchar(20),HOST_NAME())
Any help would be appreciated. (Ps. No i cannot switch to Windows Authentication in SQL Server)
I'm not sure if you can obtain the domain user name if you're not using Windows Authentication.
The most detailed info that I know of are the system tables/views, and those don't show the NT user name if you connected using a SQL login. Even if the server is in mixed authentication mode.
On pre-SQL Server 2008:
select nt_username from master.sys.sysprocesses where spid = ##spid
From SQL Server 2008 on:
select nt_user_name from sys.dm_exec_sessions where session_id = ##spid
Both will show an empty column if you connected using SQL authentication.
did you try Below command will give you NT ID
SELECT CONVERT(varchar(20),suser_sname())

SQL Server Installation issue

I have a question relating to SQL Server management studio,
I have downloaded the SQL Server Express onto my PC and was told to expect SQL Server to prompt me for a username and password, which I could use to login as "SQL Server Authentication", and use the login and password function.
I followed every single instance of the Installation but was never propted about any such password and user name setting having to be created.
Big deal however I need to practice methods for loging into SQL Server using password and Username functionality ussing vb.net (Automating login procedures).
What are the steps I need to undertake to make correct this?
The Authentication Mode can be changed at any time. In Microsoft SQL Server Management Studio, right-click on your server, and go to properties.
In the Security page, you have the option to change the Server Authentication mode to Windows or Both (Windows and SQL).
Make sure the "sa" user has a strong password (it may be empty or disabled by default).

ODBC continually prompts for password

I have an application built in Access 2003 that uses a system DSN ODBC to connect to a SQL Server. The ODBC uses SQL authentication. When the application is started, the user is prompted to authenticate into the database.
I have another computer set up within the same domain that has Access 2007 installed on it. I log in using the same credentials that I use to get on the machine that has Access 2003.
I converted my application to Access 2007 format and everything works fine. However, when other users try to use the application, they are prompted to enter the database password every time a table is accessed. Thinking it was a problem with my ODBC, I confirmed that the connections were set up the same way on both of my machines, and the user's machine.
Here is the interesting part, when the user logged into my machine, it started prompting for the password every time. When I logged into the user's machine, the application worked fine.
Anyone have any ideas? All help is appreciated!
Be sure to use a System DSN, not a User DSN. It's easy to create the wrong one since the tabs are side by side.
Make sure that the System DSN has SQL Server authentication picked and you have the login id and password set.
A User DSN is only visible to the user that creates it. A System DSN is available to all users and Windows services.

connection string for remote database server

I have 2 servers setup at the moment. One is a web server running Win Server 08 and the other is a database server running SQL Server 08 on Win Server 08.
Currently I have my site setup so that it can read/write to the database by using a connection string I created with the database name, server ip, db user and db pwd. The db user I have created has a 'public' role setup in the database (not db owner) and can just run exec stored procedures. My the connection string currently looks like this:
<add name="SiteDBConn" connectionString="Server=IPOfServer;Database=DBname;User ID=userhere;Password=passhere;"/>
While this is working perfectly for me, I would like to setup a database connection string that did not contain any username and password. On some of my other servers, where SQL server resides on the same server as the web files, I am able to use a trusted connection and use the built in 'Network Service' user on my database. This lets me run a connection string with no username and password like so:
<add name="SiteDBConn" connectionString="Server=localhost;Database=DBname;Trusted_Connection=Yes;"/>
Is there an easy way to achieve a connection to the database without hardcoding a username and password - like the above connection string - when using 2 different servers? Am I wasting my time going down this route seeing as how the database user I created has only exec permissions anyways?
Thanks for your thoughts on this.
You are not wasting your time. This is a very good practice. When you separate out IIS and SQL on separate machines, here are some options:
Create the asp.net user on both the IIS box and the SQL server (preferably with same password)
Use impersonation (change the context your site runs under)
Encrypt a connection string in the registry a config file and forget about trusted connections (brrrr)
Switch the asp.net context to be a domain user
Use IIS6 in native application mode
If the 2 servers are not in the same Windows domain, you cannot use trusted connection.
Also, the login must be created as a Windows authentication, you can't use a SQL authentication login with a trusted connection.
Otherwise, everything Tapori said.