Prompt for new SQL Server credentials in Excel - sql-server

I was creating a SQL query in excel via Data > Get Data > From Database > From SQL Server Database button. During the creation, I accidently attempted to create the source using windows authentication which will not work as I need to use SQL authentication and of course resulted in the expected error. When I try recreating the same connection to the same server it will not prompt any more for credential after adding the DB and Command and must be using the old credentials.
I tried creating a new workbook and it still will not prompt for new credentials.
I was able to successfully link another server which prompted for credentials but no longer will for the server in question.
Is there a file or location in Excel that is storing these credentials that I can remove them from? The troubled server/connection does not appear under the query/connection list in the workbook.
Any help is appreciated!
This is the error I receive and knew would occur when using the wrong credentials: Details: "Microsoft SQL: The target principal name is incorrect. Cannot generate SSPI context."

Related

Login failed for user (but not really) in SSDT in SQL Server 2017

I have a weird problem with SSDT(Visual Studio 2017 server explorer) when I try to view the tables in my Database
In SSMS (SQL Server Management Studio 2017) I created a database with a new user called admin. This user has public and sysadmin permissions and can execute CRUD queries and see the tables in the Object Explorer.
So everything is working fine... However, when I try to connect to the database from VS2017 with SSDT I succeed to connect to the server, but I cant view the tables inside the Server Explorer and it throws me the "Login Failed for user..." error. However when I try the same with the SQL Server Object Explorer it works fine:
Why do i get this error? The credentials are correct otherwise it wouldn't have worked in SSMS and object explorer. My permissions are correct otherwise I wouldn't have been able to create the table and insert data into it. Why do I get the Login failed error in the Server Explorer?
Okay so I managed to fix the "problem",
I was entering the correct credentials, but it was still giving me this error.
So what i tried this time is to eneabled the Save my password checkbox.... and it worked...
I deleted the connection and created a new connection (without checking the Save my password) and again the same error. So i enabled the checkbox again and it worked...
I think when trying to reach for the tables it re-authenticates at the SQL server, and since the checkbox Save my password was not enabled, it didnt have a password to authenticate with.
check your credentials in the properties of the connection

Cannot open database "DatabaseName" requested by the login. The Login failed. Login failed for user

Here is the scenario.I'm creating a desktop application with VB.NET (Windows Forms), and using SQL Server 2008 R2 for its database.
I have two computers (PC1 and PC2) and I want to connect PC2 to PC1.
PC 1 has the SQL Server database. What I do is I just copied .exe application in
the debug folder of my vb project and create a notepad for its connection and put them into one folder and transferred it to PC2.
When I run my application to other PC, I get an error
Unhandled exception has occurred in your application. If you click
Continue, the application will ignore this error and attempt to
continue, If you click quit, The application will close immediately.
Cannot open database "DatabaseName" requested by the login. The Login
failed. Login failed for user
My code inside the notepad
Data Source=.;Initial Catalog=DBSAS;Integrated Security=True
What I have done so far is to enable remote connection of SQL Server 2008 R2.
Can someone please give me an advice about this? I am really confused. Thanks
Hi please find sql server instance name at PC 1 using below command
OSQL -L
replace . to the instance name at you connection string.
Specify Data Source= "sql server instance name " in the connection string.
more detail are posted on below link.
How can I determine installed SQL Server instances and their versions?.
On the second pc create a txt file on desktop. Something like test.txt. Then rename it to test.udl Universal Data Link. Double click the test.udl. From there you can produce a valid connection string to the SQL Server. After you are done open the udl file with notepad to get the connection string. Hope this helps.
Specify Data Source=PC1 in the connection string. The . indicates a local SQL Server instance running on the same machine as the application. The error suggests SQL Server is installed on PC2 but doesn't contain the desired database.
EDIT:
The error
Cannot open database "DatabaseName" requested by the login
indicates authentication was successful to the SQL Server but the database context could not be set. If DatabaseName in the error message is the same one as the Initial Catalog in the connection string, then either the database does not exist or the user does not have permissions to use it. However, if the DatabaseName in the error message differs from the connection string, the connection string you changed is not the same one that is actually being used by the application.

Excel VBA connect to SQL Server Login Error

I am a beginner in Excel VBA and faced a problem: I can connect to remote SQL Server through Management Studio, but got error when connecting through Excel VBA.
Below is my connection string and the error code.
Const connection_string As String = "Provider=SQLOLEDB.1;Persist Security Info=True;Integrated Security=SSPI;Initial Catalog=RPGTFDB;Data Source=122.xxx.xxx.xxx;User ID=sa;Password=xxx"
Error is:
Run-time error (80004005): Login failed for user ". The user is not associated with a trusted SQL Server connection.
Is it not able to get the User ID?
However when I connect to local computer, like 127.0.0.1, the above connection string works.
Thanks a lot!
In your connection string you should not use
User ID=sa;Password=xxx
As the error seems to be indicating that only Windows Logins are enabled on the SQL Server and this connection string item is only for SQL Logins.
Do you have to punch in a login and password when connecting with management studio? If not then I suggest you have a database that authenticates a connection using your windows login.
If this is the case, then remove the User ID and Password bits and insert Trusted_Connection=Yes instead.
Finally, the connection string is created using UDL application.
Despite I still cannot find any difference between the string and the manual created one, it works!
Follow the instructions in this link:
http://social.technet.microsoft.com/wiki/contents/articles/1409.how-to-create-a-sql-connection-string-for-an-application-udl-file.aspx

Deployment of DB TFS MSBuild

I have the following problem deploying our ASP.net Webproject. The Deployment just runs fine. I'm using TFS 2010 and deploy the application through the msbuild arguments (/p:DeployOnBuild=True etc.).
The problem I'm running into is the deployment of our database. At the moment I'm trying to use the Package/Publish SQL settings of the web project. The connection string for the destination database looks as follows
Data Source=SomeIP, 1433; Initial Catalog=MYDatabase; User ID=DeploymentUser; Password=PW;
So I'm trying to use an sql login to login to the sql server (sql server 2012, the respective user is dbowner) but every db deployment fails because msbuild always tries to login to the sql server with the buildservice account.
One solution might be to grant access to the sql server of the build account. Unfortunately this is not possible for us because the dbserver is not in our domain.
Any ideas how i can force msbuild using the sql login specified in the connection string?
Are you doing any of this:
"Import from Web.config
Finds connection strings in the Web.config file and enters their names into the Database Entries grid with "-Deployment" appended to them.
You can change the "-Deployment" suffix to "-Web.config" (for example, change "ConnectionStringName-Deployment" to "ConnectionStringName-Web.config") in order to specify that the connection string value in the Web.config file should be used for deployment. For more information, see Connection string for destination database later in this document."
and is it taking the connection string from your web.config?
http://msdn.microsoft.com/en-us/library/dd576376.aspx

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