Failing VB.NET OleDbConnection. SQL Server does not exist or access denied - vb.net

Realise this has been asked before but i have been unable to find a solution that works in this case.
I am trying to connect to a sql database over a network. The server is 2008 and the application is VB.Net (4).
The offending script is;
Dim strConnection As String = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=XXXX;Password=XXXX;Initial Catalog=MBB;Data Source=NETPC\SQLEXPRESS"
con = New OleDbConnection(strConnection)
con.Open()
The user id and password connect and has write permission to the db
using SQL Management Studio.
I have tested the connection string using the .udl quick test where
it worked fine and matched the string above.
The db is set up to accept both windows & sql server (password
protected) authentication.
Actual error is;
An unhandled exception of type 'System.Data.OleDb.OleDbException'
occurred in System.Data.dll Additional information:
[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or
access denied.

Related

How to fix in R "Login failed for user: XXX" for connecting to SQL?

I tried to create a connection from RStudio to Microsoft SQL 2016, using the following code:
con <- dbConnect(odbc(), .connection_string = "Driver={SQL Server};Server= XXX; Database=XXX;UID=domain\\username;PWD=XXX;TrustServerCertificate=yes")
And get this error:
Error: nanodbc/nanodbc.cpp:950: 28000: [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'domain\username'.
RStudio create values but not a connection to SQL because it doesn't show up in the connection pane.
I am working on a remote desktop, have read rights and Windows Authentification for SQL Server Management Studio. DBI and ODBC package are installed.
I also tried the code WITHOUT UID and PW but then i got this error:
...Cannot open database "XXX" requested by the login. The login failed.
Then i tried this:
con <- dbConnect(odbc::odbc(), .connection_string = "Driver={SQL Server}, Server=XXX,Database=XXX,Port=1433")
And get this Error:
...Invalid connection string attribute.
Do i need more than read rights or do i need Windows AND/OR SQL Authentification?
Or do you think there is something wrong with the codes I am using?

How to open a connection on the back end in C# to a local database

I had a database server for school and since the semester is over I no longer am on this server. I want to take all my projects and put them on my website I've been working on. The problem is they have the school server connection. On the back end when I want to open a connection to my local database how would I do this? My connection looks like this
SqlConnection con = new SqlConnection("Data Source=LocalServerName;");
I get an error about the user, but my username for my local connection has a \ in it and that's an invalid key so I can't put my username in
Try this....
string connectionString = "Integrated Security=SSPI;Initial Catalog=master;Data Source=(local)"
SqlConnection con = new SqlConnection(connectionString);
You can change the value for Initial Catalog from "master" to the name of your database. I'm assuming you're using integrated security (you login to SQL Server with your Windows account).
If your login failed, look in SQL Server's error log for a failed login attempt. The error will give you more details about why the login attempt failed.
If you're logging in using a domain account - a.k.a., Windows authentication, a.k.a., Integrated Security - you'll include the following in your connection string:
Integrated Security=SSPI;
If you are connecting with a SQL Server username (username and password maintained by SQL Server and NOT by Windows or Active Directory). You'll use the following:
Persist Security Info=True;User ID=<username>;Password=<password>;
If you're not 100% sure how to create your connection string, try this trick:
Create a text file on your desktop named "test.udl"
Once created, double click on that file.
You can set all the properties of your connection string here.
When you're done, hit OK.
Then open the file in a text editor (e.g., notepad).
You'll see a connection string configured with the options you previously set. Copy and paste.

Connecting to SQL Server in Visual C#

I'll show the code I'm using, but I can't connect to SQL Server through Visual C#. I have installed what came in the C# package and I keep getting this error:
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Additional information: 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: Named Pipes Provider, error: 40 - Could not open a
connection to SQL Server)
I can't figure out how to connect to the server. I'm using Windows 8, SQL Sever 2012 (Visual Studio 2012) and if I go to connect in the top toolbar, it doesn't matter if I use (local), localhost or my IP address. I can't figure this out and its driving me nuts! Here's my code, if it helps.
private void btnSave_Click(object sender, EventArgs e)
{
System.Data.SqlClient.SqlConnection sqlConnection1 =
new System.Data.SqlClient.SqlConnection("Server=(local);Database=Database1DataSet;Trusted_Connection=True;");
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = "INSERT VALUES (id, Medname, MedDose, MedAm, MedNoon, MedEve, MedNight, MedPRN, MedOther) VALUES (1, 'Clonazepam', '2mg', 'true', 'true', 'false', 'true', 'true', 'false')";
cmd.Connection = sqlConnection1;
sqlConnection1.Open();
cmd.ExecuteNonQuery();
sqlConnection1.Close();
}
Thanks so much. This is my first time using SQL Server through Visual Studio.
If you installed SQL Server as part of the Visual Studio 2012 install process, then it installed SQL Server Express LocalDB. LocalDB is very lightweight and does not have a constantly running service. If you actually did install LocalDB while installing Visual Studio, you should be able to see the "instance" by going to the View menu in Visual Studio and selecting SQL Server Object Explorer. There should be a folder (so to speak) for "SQL Server" and expanding that should show you something along the lines of:
(localdb)\V11
or
(localdb)\Projects
Whatever that value is, THAT is what you specify for the "server=" in the connection string. So, your connection string should look more like this (due to the backslash, you should prefix the string with #):
#"Server=(localdb)\V11;Database=Database1DataSet;Trusted_Connection=True;"
Also, when you create a new project in Visual Studio, it should pre-populate the correct connection string in the Debug tab of Project Properties.
EDIT:
Also, you can find the instance name(s) in the following location as each instance will be a subfolder:
C:\Users\{YourUserName}\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances

how to remove security settings from a connection string in vb.net

hi i am trying to add data to the database that was created by some one but when am trying to insert or delete or update the exception is raising and entire project is not working properly and the error i am facing is
"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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"
so now what should i do to resolve this error and my connection string is written as
Dim CON As New SqlConnection("Integrated Security=SSPI;
Persist Security Info=False;Initial Catalog=DIGITALGAMES;
Data Source=TEJUS-PC\SQLEXPRESS")
is there any problem with my connection string ??
This error usually comes when database path is wrong i.e. system is enabe to locate the database
plz make apropriate modifications in
Data Source=TEJUS-PC\SQLEXPRESS
Dim CON As New SqlConnection("Integrated Security=SSPI;
Initial Catalog=DIGITALGAMES;Data Source=TEJUS-PC\SQLEXPRESS; User ID=yourusername; Password=yourpassword")
and
try this link
, with useful information about connection string
I think the server you are trying to access is either not in the network or you dont have windows authentication to that server.

Mysql migration tool, source parameter string | connection string for sql server

I always got failed to "fetching of list failed error".
This is my connection string in ASP.NET
"Data Source=maywood\XSQLSERVER;Initial Catalog=maywood_test;Integrated Security=SSPI"
What exactly should I input at MySQL migration tool for source parameter string
FYI,'maywood' is my computer name and I am using SQL Server 2000.
You have integrated Integrated Security=SSPI set -- perhaps you should try setting the UID and Password manually to values that you know are correct.
Data Source=maywood\XSQLSERVER;Initial Catalog=maywood_test;
User ID=myUsername;Password=myPassword;
Integrated Security uses the credentials from the Windows system that you're using to log in -- these credentials might not be valid for the database you're trying to access.