SAS connection to SQL Server DB using Windows Authentication - sql-server

Can anyone give me the libname statement for making SAS to SQL Server connection using windows authentication or is it even possible without entering userid and password?
Thanks

You will want to use a connection string that has Trusted_Connection=True; How that property is communicated to the engine is dependent on the engine.
A great resource for all things connection strings is https://www.connectionstrings.com/sql-server/

Related

IIS Connection IIS Basic User Settings Specific User Cannot Connect to SQL Server using Perl DBI

My Perl IIS web application is getting an SSL Error when the Perl DBI tries to connect to my MS SQL Server database version 11.0.7001 (that's what is listed in SQL Server Manager). The Perl application runs under IIS, and my IIS Basic User Settings Connection is set to Specific User (Domain Administrator).
The SQL Sever database resides on the same system as IIS. The distribution of Perl is Strawberry Perl; IIS' version is 8.5.9600.16384.
I can connect to the database using the SQL Server Manager locally on the server as well as remotely from my workstation. The connection type is SQL username and password. The IIS application listens on port 8085. The IIS permissions are not restricted, and there is no SQL server connection string as part of IIS.
The first page of the application loads, but this first page does not try to connect to the SQL Server database.
I have been looking at Stackoverflow posts -- like this one -- for a while, and have tried some of the suggestions like making a system DSN (which tests correctly), instead of a DSN string in Perl.
None of the suggestions have helped, and many but not all of the posts are dealing with security and certificates, not an application that is behind a firewall. In other words, I do not have security turned on.
To the best of my knowledge there is no security turned on for this application, and Named Pipes and TCP/IP were already turned on, as was suggested in one of the posts I read.
Here is the error:
[Microsoft][ODBC SQL Server Driver][DBMSLPCN]ConnectionOpen (SECCreateCredentials()). (SQL-01000) at ../../include/DbArgs.pm line 266.
DBI connect('driver={SQL Server};server=arlsql\arlsql;database=BuildingPermit;uid=user;pwd=pwd','',...) failed: [Microsoft][ODBC SQL Server Driver][DBMSLPCN]SSL Security error (SQL-08001) [state was 08001 now 01000]
Any suggestions on what to try next would be appreciated.
Edit 1/6/2020
I need to add that my C# client application using .Net ODBC objects successfully accesses the same database on which the web-based Perl DBI code fails. The username and password are the same for the client application as that used in the Perl CGI.
The IIS user for this application runs as the domain administrator, but when creating the DBI connection uses the same username and password. The database is set up for SQL username and password, and, as stated previously, there is no security set, at least that I can tell.
This does not answer the question but is instead a workaround. I consider the following a workaround, because I would still like to know why the DBI call failed with a specific user.
I switched my IIS Basic User Settings Connection from Specific User (Domain Administrator) to Application User (pass-through authentication).
After making this change and restarting IIS, the Perl DBI connection worked, but why?

Specifying login creditials for remote SQL connection string in ASP.Net/Entity Framework Core

I am following https://learn.microsoft.com/en-us/ef/core/get-started/aspnetcore/new-db to learn how to use the new .Net Core and Entity Framework Core and I am trying to create the connection string to a remote SQL Server. I updated the server and database strings but it does not show how to specify the username and password. I have done some digging but every entity framework core example I find is for localDB only. How am I to properly specify the login credentials and what should Trusted_Connection be set to for a remote SQL Server 2016 server?
The connection strings in EF Core remain the same as in EF6 and when you use pure ADO.NET.
For user/password authentication it's Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;.
For a list of common connection strings for SQL Server (and others), look at https://www.connectionstrings.com/sql-server/.
There is small difference in the connection string for the core.You can find it in the MSDN Blog.
we need to specify the server port number in the connection string.
Server = tcp:<ServerName>,<PortName>; Database = <DataBaseName>; User Id = <UserName>; Password = <Password>;
To get the server port number using the following query.
select distinct local_net_address, local_tcp_port from sys.dm_exec_connections where local_net_address is not null

Connection string for SQL Server Express 2014

On Win 7 system I installed SQL Server 2014 Express. I created instance HM1. I've set it up to use mixed mode. I created a SQL Server user and I am able to login with no issue.
My goal is to connect to a database using this SQL Server user using configuration file. This connection will be used for another application. Note: if I disable user/password usage during login I have no problem but I have to use credentials.
For connection I provided machine_name\SQLSERVEREXPRESS\HM1. I also provided username and password. I also changed the service for SQLEXPRESS and HM1 to run as local account.
When I try to connect using that file I've got the error
Can't connect to database
Again if I disable user/password usage I am able to connect using the same file with no problem.
Could someone help me with it?
Thanks
For connection I provided "machine_name\SQLSERVEREXPRESS\HM1".
You just want this:
machine_name\HM1
That's probably not your only problem, but that's all I can tell you until you try that and then come back and include more detail from the error message.
You need to put the un-encoded password in the config file instead of the base64 encoded one. Alternatively, you can also put Trusted_Connection=True; in the connection string if your database server resides on the same server as the application server. This will use the OS credentials instead of the username/password that you provide.

Which connection string should I use with an application role in MS SQL?

My client set up an application Role in Microsoft SQL Server 2008 for one database. He doesn't know how to change the connection string for that role and I have any idea about which connection string to use for this purpose.
Can anyone provide me an example of a connection string for an application role defined in MSSQL?
To not use AttachedFile in the connection you need to attach the mdf file to a SQL Server. Once attached you could use a connection similar to the one below but many examples can be found here
Data Source=myServerAddress;Initial Catalog=myDataBase; User Id=myUsername;Password=myPassword;

Can't access SQL Server file in the server machine

I setup the my WCF service on server machine.
The server OS is Windows 2008 with SQL Server 2008 Express.
I am trying to access to my SQL Server (mdf) file to read data using LINQ to SQL.
I see that the DataContext is OK - but when I try to get information that in one of the table I get an exception
Failed to generate a user instance of
SQL Server due to failure in
retrieving the user's local
application data path. Please make
sure the user has a local user profile
on the computer. The connection will
be closed.
I don't know what i need to define or change in the IIS 7.5 that I'm using in the server side.
Thanks for any help.
Update: the connection to the database file is fine - but getting information from table is thru an exception. The connection string is:
Data Source=.;AttachDbFilename=|DataDirectory|\ServiceData.mdf;
Integrated Security=SSPI;User Instance=True
If you already have a server, why don't you just attach the MDF to the SQL Server (Express) running, and then use it like a normal database on your server?
After you do this, use a connection string like:
server=Server\SQLExpress;Database=YourDatabaseName;Integrated Security=SSPI
I never quite liked the AttachDbFileName= and User Instance approach - seems like a (unreliable) hack to me, which really doesn't make sense if you're running on a server machine.
The reason that you are getting this error message is because your code is in the security context of a user that has never logged on to the server. The user therefore does not have a profile and you therefore get an error when the code attempts to write to a non-existant profile.
You could use marc_s's approach or you could run as a user that has a profile.

Resources