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
Related
I am new to SQL Server and I am trying to connect a localhost SQL Server. And I am having the following exception:
Cannot open database "MyDatabase" requested by the login. The Login failed Login failed for user "MyCodingPC\Cyborg".
And also I don't understand why it is getting logged in via that username when I have specified another user in the connection string.
My connection string
Data Source=xxx.xxx.xx.xxx,1433\(localdb)\MSSQLLocalDB;Network Library=DBMSSOCN;Initial Catalog=MyDatabase;User Id=MyNewUser;Password=pass##$word;Integrated Security=True
LocalDB cannot be used over TCP. So to accomplish my requirements I used SQLExpress instead.
LocalDB is supposed to work only for local access; remote access is not possible here.
I have a web site and I'm trying to setup a DSN instead of using a connection string because it seems more secure.
The following connection string works fine in my site:
"Server=servername; database=mydb; user id= web.account; password=PassW0rd!; Integrated Security=SSPI"
However, when I try to set up a DSN (using the 64-bit odbc admin) I get the following error:
Connection failed:
SQLState: '28000'
SQL Server Error: 18456
[Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'web.account'
Keep in mind, I'm using the same account and password I use in the connection string (which works). It's weird too because the error occurs right after I click 'Next' on the "How should SQL Server verify the authenticity of the login ID?" page.
It seems like the odbc admin does not even try to connect to the server to verify the credentials. What can I check to prove this / How can I fix this?
Things I've tried:
I have checked the server authentication mode, as proposed in other solutions, and that is set to "SQL Server and Windows Authentication mode", as it should be.
I have tried creating both a User and System DSN - both get the same error, this seems like further evidence that it's not trying to connect to the server to check the credentials.
I have tried the same DSN creation on multiple servers, all have the same problem. Is it possible the SQL Server is refusing these types of connections?
UPDATE 1:
The DBA just told me that the web.account is actually a Windows account, not an SQL account. I guess that's why the odbc isn't working, because it doesn't try to connect as a different windows user, only as the current windows user. So now the question is, how do I set up a DSN with a different windows account? Or, is that even possible?
This post has a response that says DSNs setup with NT authentication are specifically for the entire system, not a specific account, so a runas command could be used from cmd, like so:
runas /netonly /user:domain\web.account "C:\Windows\SysWOW64\odbcad.exe"
It will then ask you for the web.account password. Then you can create a DSN, and this should work.
UPDATE: I had to add the web.account user to my Administration Group using this fine how-to. Then I had to run cmd as my elevated account. Then ran the runas command I showed above. Then, I was finally able to create a non-native DSN, which allowed me to connect to the Data Server as a different Windows user.
Still waiting for DBA to check the logs to say this actually worked or not, but I feel pretty good about it. Will update after confirmation.
Try the following:
Data Source=servername;Initial Catalog=mydn;Persist Security Info=True;User ID=web.account;Password=Passw0rd
This is what I use to connect.
I want to test a connection using SQL Server that can access through internet but I'm lost, I don't know where to start.
I know how to do it in MySQL but I want to know how to do it in SQL Server.
Thanks in advance.
One quick trick I know of, which works even on machines without SQL tools installed:
Create a new blank file somewhere and give it .udl for an extension. It should change to an icon with a table and a white page with 0s and 1s in the background.
Double-click on it to open the "Data Link Properties" dialog
On the Provider tab, choose "Microsoft OLEDB Provider for SQL Server"
On the Connection tab, fill in the remote server details and credentials
Click "Test Connection"
Where to start?
Try looking for the correct connection string here
You then need to find an example using the System.Data.SqlClient
By 'connect through the internet' do you mean connect from the internet to a SQL Server?
You need to open appropriate ports in the firewall and NAT them to your SQL Server.
To get you started, I would install a copy of SQL Server Express onto your local workstation and create an SQL Server instance with SQL Server Authentication. Also install SQL Server Management Studio which is a visual console through which you can manage your database and logins etc. They are available for free here:
http://www.microsoft.com/en-us/download/details.aspx?id=29062
Go into SQL Server Management Studio, create a database and a login username and password with sysadmin rights. Connect using the following code. The principles are similar to connect to an SQL Server database over the internet only there are more security issues to take into account.
Dim sConnectionString As String = "Server= MYCOMPUTERNAME\SQLEXPRESS;Database=DATABASE_NAME;User ID=USER_ID;Password=PASSWORD;Trusted_Connection=False;
Try
Dim mySqlConnection As New System.Data.SqlClient.SqlConnection()
mySqlConnection.ConnectionString = sConnectionString
mySqlConnection.Open()
MessageBox.Show("You have connected successfully to the SQL Server database.")
Catch SqlEx As SqlException
MessageBox.Show(SqlEx.Message & Constants.vbNewLine & Constants.vbNewLine & "You have NOT connected successfully to the SQL Server database.")
Catch ex As Exception
MessageBox.Show(ex.Message & Constants.vbNewLine & Constants.vbNewLine & "You have NOT connected successfully to the SQL Server database.")
End Try
I have SQL Server 2010 running in windows auth mode and the proper groups have been assigned. I can connect via the SQL Server Client Studio using windows auth. That works. But when connecting using .NET OLEDB connections it fails and I can't figure out why.
Here is the string:
data source=172.20.0.113;initial catalog=ForgeEnterprise;Integrated Security=SSPI;multipleactiveresultsets=True;App=EntityFramework
And here is the error:
Login failed for user 'MOMENTUMI\jmcclure'
Is there something I'm missing?
According to http://connectionstrings.com/sql-server-2008 this should do the trick
Provider=SQLNCLI10;Server=172.20.0.113;Database=ForgeEnterprise;Trusted_Connection=yes;
Where Trusted_Connection is the same as Integrated Security apparently.
If that doesn't work, you should verify that the user is added in the permissions tab (picture) for the database, but I guess you already did that.
It installed automatically with Visual Studio 2010 Ultimate. I didn't create any users for the server or ANYTHING.
I'm using:
string connectionString = #"Server=.\SQLEXPRESS;Database=SportsStore;Trusted_Connection=yes;";
I get error that authentication failed. So the server is being found, but my credentials are wrong. What would the default login and password be?
Edit: Still not working! :(
Here's my connection string:
string connectionString = #"Server=.\SQLEXPRESS;Database=SportsStore;Integrated Security=SSPI;";
And the error message:
Cannot open database "SportsStore"
requested by the login. The login
failed. Login failed for user
'ToshibaLaptop\Sergio'.
If you are using SQL Server authentication you could try the username sa and blank password but I am not sure whether this is by default. Integrated Windows authentication should work, so you should be able to connect with your Windows account:
string conn = "Data Source=.\SQLExpress;Initial Catalog=mydb;Integrated Security=SSPI;";
You probably should not connect using Sql Server Authentication.
Log in as an Administrator on the box, connect using Integrated Windows Authentication, and you should be a system admin.
The error message indicates that SQL Server can't open the database. I think you're successfully authenticating, but having a problem connecting to the database. Is the database available?
You can do a test by changing the database to master in your connection string. If that succeeds, then you're problem is related to the database. I understand that you may get other errors, but the test is to confirm that you can login to SQL Server.
For me SQL Server (SQLEXPRESS) service was disabled so it was throwing the error. After enabling the service SSMS is working fine
Goto Run command and type services.msc and click on OK button
Services window will open. Check the status of SQL Server (SQLEXPRESS) service
If the service is not running, then start the service
Now try logging in again in the SSMS.
In SQL 2008 if you use the defaults there won't be a SQL Server user only Windows Authentication will be enabled - and it will only work for the user that installed the application would have access via their Active Directory authentication.