Unable to connect to SQL LocalDB - sql-server

I have a native C++ app within which I am trying to connect to a localdb instance using ADO. Having manually started my instance I can run sqllocaldb info v11.0 and see the database instance is running.
My code is as follows.
ADO::_ConnectionPtr spConnection (__uuidof (ADO::Connection));
spConnection->Open (L"Provider=SQLNCLI11;Server=(localdb)\\v11.0;Integrated Security=true", L"", L"", 0);
The error code is DB_E_ERRORSOCCURRED (0x80040e21) and the error message is Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.
I am able to successfully connect to the database using SQL Server Management Studio and I've tried it both with and without the provider in the connection string as well as specifying an initial catalog.

I found my issue. The security must be set to sspi as shown below.
ADO::_ConnectionPtr spConnection (__uuidof (ADO::Connection));
spConnection->Open (L"Provider=SQLNCLI11;Server=(localdb)\\v11.0;Integrated Security=SSPI", L"", L"", 0);

ADO connection object has an Error collection that holds the list oft error that has occured so far. You can take a look at these error to see what's wrong.
Usually two things can go wrong while connecting to SQL Server.
1.Login Failed.
2.SQL Server is not configured so that you can connect to it remotely.
Since you are trying to connect to a local server it can hardly be the second reason.
As you might now there are two different type of authentication when it comes to SQL Server:Windows and SQL Server.You can use one of therm if each of them is set in your SQL Server options or both of them if the mixed mode is selected.
According to your connection string you are using windows mode authentication therefor you should be logged in using a windows user that can login to SQL Server.If that's not the case with your SQL Server then you should provide a SQL user credentials in your connection string.
Anyway check the Error collection of connection object as see if there's anything else is wrong with your local db.

Related

Unable to connect to another connection in SSAS Tabular

I have a very weird issue with SSAS Tabular connecting to a SQL Server source database. I've spent almost the entire day on this, and searched online in various ways to find a helpful answer, but none of the suggestions solved this mysterious problem for me.
It used to work fine, but I tried various connection settings (Windows vs SQL authentication, and different impersonation modes), but now I no longer can get it to work (even if I revert back to the previous bim file in source control).
When I process a table from the WORKSPACE database (through SSMS), it works. But when I process a table from the DEPLOYED database (still through SSMS), it does NOT work.
The connection I am using is:
-SQL Server Native Client 11.0
-Windows Authentication
-Impersonation mode of a Windows account (which has the appropriate permissions)
The source database is in a SQL Server database located on a different server (but in the same network).
I have searched everywhere online, but didn't find anything that could help me.
I have tried changing the connection driver (OLE DB Provider for SQL Server), and I have restarted the SSAS Tabular service.
The full error message I get when trying to process a table on the deployed database is:
Failed to save modifications to the server. Error returned: 'OLE DB or ODBC error: Login timeout expired; HYT00; A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.; 08001; Named Pipes Provider: Could not open a connection to SQL Server [5]. ; 08001.
A connection could not be made to the data source with the Name of 'DataWarehouse'.
'.
In fact, after I tried a second time to restart the SSAS Tabular service, the error message I get after attempting to process a table is slightly different:
Failed to save modifications to the server. Error returned: 'OLE DB or ODBC error: A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.; 08001; SSL Provider: The requested security package does not exist
; 08001; Client unable to establish connection; 08001; Encryption not supported on the client.; 08001.
A connection could not be made to the data source with the Name of 'DataWarehouse'.
'.
According to your description, it seems to be related to connection problem. You need to check whether corresponding SQL server service and SSAS Service is running(check server which contains "DataWarehouse" is running and can be connected). You could go to "SQL Server Configuration Manager " to restart them.
In addition, you also need to make sure your current windows credential can access this database(if you use window credential). And check whether this server enable remote connect.
Zoe

SQLSERVER 2008 Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection

I am using SQL SERVER 2008 R2 and I have a job which runs a DTS daily. When I try to execute the DTS package it works but when I try to use the scheduled job it returns the error:
Error:
-2147467259 (80004005); Provider Error: 18452 (4814) Error string: Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection. Error source: Microsoft OLE DB Provider for SQL Server Help file: Help context: 0. Process Exit Code 1. The step failed.
How can I solve that?
Follow the below steps:
1. Start > Programs > Microsoft SQL Server 2008 > SQL Server Management Studio.
2. In the Object Explorer, right-click the Server and select Properties.
3. In the Server Properties dialog box select the Security page.
4. Under Server authentication, select SQL Server and Windows Authentication Mode.
Then restart the server.
For further reference check this.
I stumbled across this issue and spent lot of time.
Finally found the issue is not in any user settings but my publish settings are overriding my connection string.
In web deploy settings there is an option to override your web.config connection string. Either untick that option or place the correct connection string.
For more details see this post https://dba.stackexchange.com/a/141243
I am placing this answer in case anyone gets stuck like me. :)

Login Failed on SQL Server 2014

I'm having issues connecting to a SQL Server 2014 database using Management Studio with SQL Authentication. This server was just created by my IT department. I restored a database, I added the login with a password, I made sure the server properties had both SQL Authentication and Windows Authentication checked. I made sure the user at the database level is mapped to the login. But when I try to connect using Management Studio I get the following error. However, it works if I use my Windows Authentication account.
Actually, I kept getting the normal 'Login Failed' message. But this morning I got the above error which is probably more helpful. When I kept trying again, I kept getting the normal Login Failed message.
Have you seen this Microsoft TechNet post about the message you received? It looks like your admin may need to adjust the SQL Server configuration.
Specifically, it looks like you might need to try one of:
Connect using TCP/IP, or use the SQL Server Configuration Manager to
enable remote connections using named pipes.
or...
Using SQL Server Configuration Manager on the client computer, move
TCP before named pipes in the protocol order list.

ssrs DB connection error

I'm Trying to created a shared Data source from a sql server that is not local. the host of SSRS is a sql server 2014 and the DB source is a sql server 2008 R2.
I'm getting the same error whatever I do, which is
"An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"
I know everything is correct because even though I get this error when I run the report, in MSSQL report builder when I create a dataset and go to query designer and run the query it actually runs without any issues.
furthermore also in report builder when I try to do a connection embedded in my report and when I'm in the connection builder (connection properties) and I test the connection from there it gives me "the test connection suceeded" however when I click ok, go back to the datasource properties, and click "test Connection" it fails and gives me the error above.
If I try to test a shared connection on the server it will fail too.
I've tried connecting in many different ways (using windows athentication (my user is admin on the server), SQL server authenticationm, promting, etc) but they all failed.
I've been at this for a while, the server is also accesed by a remote PHP server so I doubt there is any real issue on the SQL server. I've tried deactivating all of the firewalls I saw but I doubt it's a firewall issue since I"m able to do all these connections.
the issue was the port 1433 that didn't work between the SSRS server and the datasource server. however it did work between my computer and the sql server.
what was happening is that when I tested the connections, the first test was a quick test and went through my computer to test the connection thus it was sucessfull. when it did the real test it went through the SSRS server and it failed there.
the same logic applies when I did my requests, when I tested the dataset it worked because in report builder it went directly to the database through my computer, when I tried to run the report it went through the SSRS server and failed there.
so there is some issue with the firewall even though it is turned of on both servers it's the connection between the two that isn't working.

Error while trying to connect to SQL Server - localhost

I have checked the instance name, auto close is set to true, allow remote connections on the server is checked. The server is running when I open the SQL Server configuration manager. I have even rebooted. I have created this db the same way as all others. I use Entity Framework and have checked the names in the web.config and they match. This is the default connection string from the wizard - I use for testing before I deploy. I just can't think of anything else to check to figure out why it won't connect. Working inside SQL Server everything is fine.
Here is the general error.
A network-related or instance-specific error occurred while establishing a connection to SQL >Server. The server was not found or was not accessible. Verify that the instance name is >correct and that SQL Server is configured to allow remote connections. (provider: Shared >Memory Provider, error: 40 - Could not open a connection to SQL Server)
Config:
connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string='data source=.\SQL_1;attachdbfilename="C:\Program Files (x86)\Microsoft SQL Server\MSSQL10_50.SQL_1\MSSQL\DATA\A_db.mdf";integrated security=True;connect timeout=10;user instance=True;multipleactiveresultsets=True;App=EntityFramework'" providerName="System.Data.EntityClient" />
Thanks in advance.
Let me preface this answer by saying that proper setup of a SQL instance is not as easy as Microsoft would like you to think with the entity framework. It's a little bit involved and requires that you put your DBA hat on for a little bit.
The error you have indicates that the web instance is attempting to connect to the SQL server using Windows Integrated Security. This will work fine if (a) the windows user that the process is running as (which can be configured in IIS) is authorized to log on to the SQL server and has a valid login in the database and (b) if the SQL server is on the same machine or in the same domain as the IIS server.
In light of this, I recommend using SQL Server authentication. If you need to know how to do this, I recommend searching for "SQL Server Authentication setup" - here is an article that I found which might help you set this up.
http://msdn.microsoft.com/en-us/library/aa337562.aspx
In general, I recommend taking the following actions:
Connect to the sql server using MS SQL Management Studio.
Permanently attach your database, then use the Initial Catalog property on your connection string rather than AttachDbFileName
Then set up your login username and password on the SQL server, and create a login in the database for it.
Make sure your login can only execute the stored procedures you want it to execute. Deny it access to running sql statements.
You will also need to add the username and password to your connection string, and set IntegratedSecurity=false.
Let us know how things go once you get your SQL server set up properly.
This error means that your provider code cannot find the SQL Server. If you have checked the server instance name (it should be <yourLocalServer>\SQL_1), then it could be the attachdbfilename= parameter, as this is a really unreliable way to specify the database to connect to (you should be using the Database Name, not the file name), because there are about a hundred reasons that the file name could change that have nothing to do with your application.

Resources