I am using c# on monodevelop on Ubuntu x64.
I am trying to use Mono.Data.Sqlite to connect to a local (localhost) database but I cant connect to it.
This is my connection string:
string connsqlstring = "Server=localhost;" +
"Database=wsep;" + "User ID=root;" + "Password=1234;" + "Pooling=false";
But I keep getting:
System.Data.SqlClient.SqlException: Server does not exist or connection refused.
I have started the server (sudo /etc/init.d/mysql start)
What am I missing?
Simply put, SQLite isn't the same thing as MySQL. They're different databases.
SQLite is a flat file database, the mono side of which you can read about here.
MySQL has information on the mono website and that page also provides links to downloading the MySQL connector for use with your mono projects. You will want to look at these links for working with MySQL.
Related
I created two sample C# Console apps, one running on .NET Framework 4.6.1 and the other running .NET Core 3.1. BOTH apps are identical with the following code for Program.cs:
using System;
using Microsoft.Data.SqlClient;
namespace DBConnectTest
{
class Program
{
static void Main(string[] args)
{
string connStr;
Console.WriteLine("Type Connection String: ");
connStr = Console.ReadLine();
using (SqlConnection connection = new SqlConnection(connStr))
{
SqlCommand sqlCommand = new SqlCommand("SELECT 'Hello' UNION SELECT 'World';", connection);
sqlCommand.Connection.Open();
sqlCommand.ExecuteNonQuery();
}
Console.WriteLine("Succeeded! Done.");
Console.Read();
}
}
}
NOTE 1: I am using nuget package Microsoft.Data.SqlClient on both projects for consistency.
For input, I would copy/paste a Connection String. Sample:
Data Source=UATSOMEENV01;Initial Catalog=SomeDB_Name;Persist Security Info=True;Integrated Security=SSPI;App=SampleApp
Note 2: The SQL Server is NOT local to the server running the Apps.
Here's where it gets interesting. I run the .NET Framework 4.6.1 App executable and it connects to the DB just fine.
However, when I run the .NET Core 3.1 App executable, it fails to open a connection to the DB. Here's the error message:
Core-Error-JPEG
I have read many other questions on the internet regarding issues with connecting to the DB, but it always seems to be some issue with getting the Connection String just right. In this case, I know it's right because it works on 4.6.1 (unless .NET Core expects it differently).
Other note-worthy items:
As an alternative, I have generated a Connection String from a .udl file that connects successfully. However, that also does not work when running the .NET Core 3.1 executable.
DB Server referenced in Connection String is an MSSQL server on an AON cluster.
Using Sql Server Authentication (sa account) instead of Windows Authentication on Connection String outputs the same behavior.
Running the apps from the local DB server works on BOTH apps. ie: Using the following Connection String works when the executables are ran locally from the DB server:
Data Source=localhost;Initial Catalog=SomeDB_Name;Persist Security Info=True;Integrated Security=SSPI;App=SampleApp
Any help with this would be greatly appreciated. Thanks in advance!
After some investigation and reading, I found I had to add a port number to the connection string in order to get this to work. From before, which did not work:
Data Source=UATSOMEENV01;Initial Catalog=SomeDB_Name;Persist Security Info=True;Integrated Security=SSPI;App=SampleApp
Working Connection String:
Data Source=UATSOMEENV01,6000;Initial Catalog=SomeDB_Name;Persist Security Info=True;Integrated Security=SSPI;App=SampleApp
If you're unsure which port number to use, try 6000 or 1433 - these seem to be commonly used ones if not set otherwise. If neither of those work, try the following steps to verify which port number your Database is using:
Open SQL Server Configuration Manager (on SQL Server where the Database lives on).
Left pane, expand SQL Server Network Configuration.
Select Protocols for MSSQLSERVER. Your SQL Server name might be different.
Right pane, right-click on TCP/IP and select Properties.
Go to the IP Addresses tab and scroll to the bottom.
Under IPAll, the port number you're looking for is the value for TCP Port.
Some useful links for further reading:
Unable to create connectionstring for a remote desktop for a C# application
.NET Core canĀ“t connect to SQL DB
Check Compatibility of your sql client version with .NET 3.1
There must be issue there.
You will need to get older sql connection client in order to match your .NET core 3.1
I am creating a POS system in Windows Forms (C#) in which I use a SQL Server database file (.mdf) to store items (completely offline). When I install the application on my computer, it works fine, but when I install it on my clients PC, an error happens:
(provider: SQL Network Interfaces, error: 52 - Unable to locate a Local Database Runtime installation"
I read somewhere that the problem is caused due to the fact that the connection string of the database of my client's PC is different. I tried to add the connection string dynamically on runtime but again it only worked on my computer.
Another reason that might be causing the problem is that I used 'server-based database' since local database option isn't available in Visual Studio 2017 for some reason.
Another solution I looked up stated that I should install SQL Server Express on my client's PC. That also failed (maybe I have to set it up in a way or something).
I also tried adding the database.mdf and database_log files in the setup folder.
Lastly I tried installing 3rd party installers (Advanced installers 15.8 and InstallShield Wizard in VS 2015) which also failed.
(I have provided the code for the connection of database taking place and the connection string)
public void ConnectToDB()
{
DBConnection = new SqlConnection(#"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename=C:\Users\SAIM NASSER\Desktop\app layer\data layer\Database1.mdf; Integrated Security = True");
DBConnection.Open();
ResultSet = new DataSet();
}
If I understand you correct, you want to use LocalDB
That means using Sql Server without installing a full sql server, but just the localdb part from sql server express.
For this to work you need to install the LocalDB Driver, which can be found here
https://www.microsoft.com/en-us/download/details.aspx?id=29062
You need only the ENU\x64\SqlLocalDB.MSI
This is the only thing you need to install in your clients computer, I believe it can also be installed silent, you have to research a bit for that.
And yes, you also should change the connection string on the clients computer, you need to alter it so it points to the MDF file on the clients computer, because that location will probably be different then on your computer
EDIT
To get the connection string working, you can try this
On the clients computer, create a text file and rename the extension to .udl
So for example you have a file test.udl
Now from explorer, double click it, this will open the datalink editor.
From here you can enter/choose different settings, and click on the test connection button.
Once you get a working connection, save it, and open this file with notepad.
Inside you will find the working connection string
Hope this helps
I have a simple MVC app I'm working on. I'm trying to connect to a MSSQL server using Entity Data Model (code first from database). After successfully adding the data using the Entity Data Model Wizard, the code below throws the error "The provider did not return a ProviderManifestToken string". The inner exception is "Unable to connect to any of the specified MySql Hosts. The thing I can't figure out though, is I'm not using MySql anywhere in the project. Searching in the project explorer for "MySql" turns up nothing. Doing a Ctrl+F and searching for MySql also returns nothing found. My web.config only has the one connection string in it for the MSSQL server connection. What can I do to figure out why my project is trying to connect to this unknown MySQL server?
My code:
string something = kyg.Products.FirstOrDefault(m => m.ItemNo == "128676").ShortDescription.ToString();
I don't have an issue with the MSSQL server - I have many apps that are running successfully on the same connection. I just can't find this unknown reference to a MySql server. Any Ideas on where to look/what to try?
Edit
I felt it is worth mentioning that I inherited this project, and can't confirm what development was done on it prior to me taking it over. Also, I was looking through the files, and did find MySql.Data.dll, MySql.Data.Entity.EF6.dll, and MySql.Web.dll. I moved these files out of the bin folder, and now receive a different error -
File Not Found - Could not load file or assembly MySql.Data.Entity.EF6.dll - so something is trying to reference that dll, I just can't figure out what or where it is coming from.
Thanks in advance,
I am trying to connect to a database which is an .mdb file from my web application on asp.net. This error comes up 'Microsoft.ACE.OLEDB.12.0 Data Source =C:\Users\KIKI\Desktop\ASP.net labs\Erg8\Erg8\ebookstoredb.mdb' provider is not registered on the local machine. The thing is that on my connection string I don't use version 12 but 4. I tried installing Microsoft Access Database Engine 2010 Redistributable which gives me the option to select version 12 when I set it the connection from the "Server Explorer" window but the error is still there. Any ideas? I have spent hours looking for a solution...
Here is my connection string:
OleDbConnection constring = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\KIKI\\Desktop\\ASP.net labs\\Erg8\\Erg8\\ebookstoredb.mdb");
Also, I tested the connection when I set it and a message "Connection Succeeded" came up. The problem seems to be when I run the application on the browser.
I've been searching for a solution to my doubt but couldn't find anything more relevant than an installation issue, which isn't a problem in my case.
I am trying to execute a C# project (similar to this) that creates a local cube (.cub) file and processes data taken from an existing processed cube on Analysis Services 2012.
The project runs correctly when I use a connection string for output cube that points (and hence writes) to another database on Analysis Services. But when I execute the project using the following connection string that points to the local cube file to be created, it gives me errors depending on the version of ADOMD library referenced.
conn.ConnectionString =
string.Format( "Provider=MSOLAP;Data Source={0}", "c:\\output\\mycube.cub" );
When referenced to ADOMD 11 library, I get the following errors:
OLE DB error: 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; Client unable to establish connection; 08001; Encryption not
supported on the client.; 08001.
Errors in the high-level relational engine. A connection could not be made to the data source with the DataSourceID of 'DB_NAME', Name of
'DB_NAME'.
When referenced to ADOMD 12 library, I get the following error:
A connection cannot be made. Ensure that the server is running.
Although, I know SQL Server Analysis Services are running when I checked in services.msc.
Figured it out. I was missing a reference to the assembly Microsoft.AnalysisServices.dll