Connect SQL Server 2012 with Symfony2 - sql-server

I want to connect my project Symfony2 with SQL Server, so I downloaded the Microsoft Drivers for PHP for SQL Server from this link: https://www.microsoft.com/en-za/download/details.aspx?id=20098
and I extract it into wamp\bin\apache\Apache2.4.4\bin and I restarted the wamp server.
But when I want to create my database and my tables from my symfony project I got this error :
[PDOException]
SQLSTATE[HY000] [1045] Access denied for user
'PC-RAMI\rami'#'localhost' (using password: YES)
This is my parameters.yml file :
parameters:
database_driver: pdo_sqlsrv
database_host: 127.0.0.1
database_port: null
database_name: test
database_user: PC-RAMI\rami
database_password: "password of my PC"
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
secret: a5142e8af29ca527a8d9f3a6993ba894c4bf5ed9
this is the authentication interface of sql server

SQL server uses two methods for login.
SQL Server Authentication - you have to provide username and password (same like for MySQL etc.). If you want to use it, you have to configure your SQL server for mixed authentication. Default user is sa.
Windows Authentication - you want to use credentials of some local/domain Windows account.
You are trying to use the second method (I guess from your screenshot). Solution is setting up username and password to null (~ in YAML).
database_user: ~
database_password: ~
The reason is in sqlsrv extension. If you provide username and password it always tries to connect by SQL Server Authentication instead of Windows Authentication. But, what will PHP use as credentials? It takes credentials from process itself. Probably, you will have to run Apache2 under target credentials.
If your SQL server is configured in mixed mode. You can also create new database user account (not coming from any Windows account) and use standard username/password approach.

Related

Getting The login is from an untrusted domain and cannot be used with Integrated authentication

I have a windows authentication user created on SQL server. I am trying to connect SQL server using that user, but I am getting java.sql.SQLException: The login is from an untrusted domain and cannot be used with Integrated authentication. error.
I am using jtds-1.3.jar. My connection url is jdbc:jtds:sqlserver://xyz.net:1433;instance=dev;databaseName=XYZ;integratedSecurity=true;useNTLMv2=true;domain=XYZ.net
I have checked the connection and traffic is allowed between my client machine and server. I tried setting intgratedSecurity= false as suggested in other answers but that did not work.
What properties of user should I check to know that user is correctly configured on SQL sever for JDBC connectivity?
Finally, got this connection working. It turns out the best way to connect to SQL server using jTDS driver is to create SQL server user avoid creating windows user. And stick to SQL server based user.
The message The login is from an untrusted domain and cannot be used with Integrated authentication can be misleading. For example you can get it by entering the right username with the wrong password.
Without knowing the exact configuration of your SQL server is difficult to say but I would try with a simpler connection string:
jdbc:jtds:sqlserver://xyz.net:1433;databaseName=XYZ
I don't use jTDS directly but the version embedded inside Aqua Data Studio and we don't use named instances but, anyway, I provide the configuration I use with freeTDS in a Linux box as an example of a simple configuration that works perfectly against an cluster instance of SQL Server 2014.
In /etc/freetds/freetds.conf:
[conn1]
host = host.dom.ain
port = 1433
tds version = 7.4
Query from the command line using tsql:
/usr/bin/tsql -S conn1 -U DOMAIN\\USER << SQL_DATA
SELECT getdate();
GO
QUIT
SQL_DATA
Password:
locale is "es_ES.utf8"
locale charset is "UTF-8"
using default charset "UTF-8"
1> 2>
11-11-2022 01:26
(1 row affected)

SQL Server connection user varies when using '127.0.0.1' vs 'localhost'. Why?

When I attempt to connect to my local, default SQL Server instance via SQL Management studio using Windows Authentication, I successfully connect when I use Server Name "localhost", but fail when I use Server Name "127.0.0.1". With login auditing enabled for both failed and successful logins, I see that the successful logins are recorded as:
Login succeeded for user 'AzureAD\RealUsername'. Connection made using Integrated Authentication. [CLIENT: < local machine >]
And the failed logins are recorded as:
Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'. Reason: Could not find a login matching the name provided. [CLIENT: 127.0.0.1]
Possibly relevant:
I can connect using the ip address if I use SQL Server authentication (since I am forcing it to use an existing login).
There is no entry in my hosts file for "localhost", and when I ping localhost it does resolve to 127.0.0.1.
The SQL instance uses port 1433.
The issue, with very little variation, persists when connecting via SQL Management Studio, a .NET web app running in a local IIS instance, or via UDL file on my desktop.
Here is my question: Why would changing only the server value ('localhost' vs '127.0.0.1') change the identity used when connecting?

SQL Server 2016 Remote Connection Error 18456

I have recently installed SQL Server 2016 on Amazon EC2 instance so I can start developing various SSIS / SSRS applications.
I have enabled Remote connections, opened port 1433 in the security group and windows firewall, and created a user 'myuser123' who is enabled and and allowed SQL Server and Windows Authentication within the server properties.
I am trying to login using this connection
ec2-1-2-3-4.eu-west-1.compute.amazonaws.com\MSSQLSERVER,1433
SQL Server Authentication
username: myuser123
password: #########
The error message I am getting looks to be a user authentication error.
Cannot connect to ec2-1-2-3-4.eu-west-1.compute.amazonaws.com\MSSQLSERVER,1433
Additional Information
Login failed for user 'myuser123'. (Microsoft SQL Server, Error 18456)
However when I Remote Desktop to the EC2 Instance and try to log in locally using the same username / password I don't have any problem.
Do you have any idea why this may be?
Thanks
M

Connect to database over internet

I'd like to connect to my MS SQL database hosted on another computer over internet.
What I did:
-> I'm using NO-IP (dynamic DNS)
-> I created SQL Authentication Account and I can connect to it from local computer using MSSMS like this:
Server name: local_ip\SQLEXPRESS Login: ###, Password: ###
-> I disabled firewall
-> I set port in SQL Server Configuration Manager (to 49XXX) and forwarded this port AND 1434 in router settings to my computer
-> SQL Server Browser is running
Now I'd like to connect to this DB from another computer (different network): Server name: tcp:my_no_ip_name.ddns.net,49XX Login: ###, Password: ###
I can't connect. All the time I get "Cannot connect to my_no_ip_name.ddns.net"
Am I missing something?
on local ssms, try to connect as yourserver.ddns.net,portnumber\instancename. windows authentication doesnt work on mine but ok with sql server authentication (try to avoid using sa account). dont forget to port forward on the router and open port in sql server firewall. Leave the ports on default (1433) in config manager. Not the most secure but once it works you can harden it by changing it to a non-default port and using a more secure user id in sql server logins which only has access to the database you want...

Sql Server 2005 login failed

I'm getting message login failed user not associated with a trusted Sql Server Connection
It's a Sql Server 2005 legacy system with linked servers. Whoever set it up left sa password blank (I will be changing.)
How do make a trusted Sql Server connection ?
A "trusted SQL Server connection" error usually means that you're attempting to authenticate using Windows Integrated security and the currently logged on Windows user has not been defined either directly or through group membership to have access to the sql server database being requested.
If the sa password is indeed blank you can login using sql server security as sa + [blank] and associate your Windows account with the appropriate server permissions (and change that sa pwd just after you verify your new account works ok...)
From code a Windows Integrated connection string looks like this:
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;
a SQL Server user id/pwd connection string looks like this:
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
(for more varieties check out connectionstrings.com)
Good luck!

Resources