How to repair SQLServerCE Database programmatically - c#

How can I repair SQLServerCE Database from C# code.
I am using this call:
engine.Repair(GetDBConnectionString(), RepairOption.RecoverAllOrFail);
where GetDBConnectionString() is a private function that builds Connection String for me.
But this raises exception:
"The file that is being referenced is not a SQL Server Compact database file format"
Regards,
Pawel

You are using the wrong ADO.NET version in your own app. I think you may get this error if you use version 3.5.1 against a 4.0 database

Related

Visual Studio - Failed to link MySql database table to DataSet

When I try to drag a MySQL table to a DataSet after successfully adding a connection to a database in Server Explorer, I receive two error messages, one after the other:
"Some updating commands could not be generated automatically. The database returned the following error: Unexpected error."
"Mouse drag operation failed. Could not retrieve schema information for table or view."
Based on answers for similiar problems, I reinstalled 'MySqlConnector/Net' and 'MySql for Visual Studio', and the same problem persists. I would like to know what is going wrong.
I found the solution. After hours and hours of tinkering I found out that the current versions of MySql-for-visual-studio and MySqlConnector/Net have a bug, which can only be fixed by unninstalling those and installing MySQL-for-visual-studio-1.2.6.msi and MySqlConnector-6.9.8.msi, exactly in this order.
This worked, except I had to install 1.2.7 before I could get MYSQL to show up as an option as data provider.
in my case the error statement was "you have a usable connection already" rather than "Unexpected Error" when adding a table as a data source, the above solution with MySql for VS 1.2.7 and MySql .net connector 6.9.8 worked for me as well. these need to be installed in the exact order as mentioned above. I'm using VS2017 15.9.11.

Connecting to local SQL Server database file

I have a WPF application connecting to a local SQL Server database file (.mdf). I am using Entity Framework.
Connection string is:
Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\db_SmartPOS.mdf;Integrated Security=True
The directory is changed to the following:
string doc = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
AppDomain.CurrentDomain.SetData("DataDirectory", doc + #"\SmartPOS\");
I have copied the .mdf files manually to that specified directory, tested it, and everything is working well on my main machine, where SQL Server 2014 is installed.
Now I am deploying the app to another PC, where I installed SQLLocalDB. However, whenever I try to connect to the database, I get this exception:
System.Data.EntityException. The underlying provider failed to open --> Sysmte.Data.SqlClient.SqlException.....The specified local db instance does not exist.
The .mdf and log files are placed in the directory specified above. I have also tried to copy them to the directory where the application is installed.
I am wondering what am I missing?
So here how it worked.
First of all I found an article online that specified that the connection string in SQL 2014 is different than the one in SQL 2012, therefore Data Source=(LocalDB)\MSSQLLocalDB used in 2014 should be switched to Data Source=(LocalDB)\v11.0. If using Entity framework, this should be done the connection strings settings and in app.config.
Once this was done, i tested it on the other system, and the exception error changed. This time the application was able to connect, however there was something wrong with the versions and i was unable to access it.
I downloaded SQL server 2014 localdb engine and replaced the 2012, and everything worked fine!
Hopefully this will help someone

error in connection c# with oracle 11g 64 bit machine?

My c# form has an error in the connection from c# with oracle 11g express edition, I've put my connection string in app.config file. This is my connection string:
add name="ConnectionString" connectionString="Provider=MSDAORA;Data Source=localhost;Password=LIB314;User ID=LIB_DB" providerName="System.Data.OleDb"
When I want to run a query, it gives me error saying
The 'MSDAORA' provider is not registered on the local machine
I use Windows 8.1 Pro x64... Can anyone please help me?
UseORAOLEDB.ORACLE rather than MSDAORA.
Check below URL
https://community.oracle.com/thread/1022162
Thanks
Nipun
Try using OraOLEDB instead of MSDAORA. Register OraOLEDB11.dll using regsvr32.exe.
To do so, open command prompt and browse to the BIN folder of under your Oracle HOME's installation path (probably oracle\product\11.2.0\dbhome1\BIN) and execute the following line:
>regsvr32.exe OraOLEDB11.dll
Also, ensure verify that the PATH variable is set properly and points to Oracle's installation path i.e.: C:\oracle\product\11.2.0\dbhome1\BIN

Failed to load native dll (C:\Users\[Username]\AppData\Local\Temp\...\dbdata.dll

I'm trying to create an SAConnection into a Sybase IQ database. I'm attempting to create the connection through a simple visual studio C# application.
My code fails at:
SAConnection connection = new SAConnection(connString);
And pops up with a message box:
SQL Anywhere ADO.NET DataProvider
Failed to load native dll (C:\Users\<Username>\AppData\Local\Temp\{16AA8FB8-4A98-4757-B7A5-0FF22C0A6E33}_0\dbdata.dll
Link to picture of messagebox
The code subsequently throws an exception:
"The type initializer for 'iAnywhere.Data.SQLAnywhere.SAConnection' threw an exception" with InnerException as described in the message box.
I've checked and double checked the connection string and am confident it is correct. I am using iAnywhere.Data.SQLAnywhere version 11.0.0.11292 and am connecting to a Sybase IQ
database. I am running Win7 64 bit and can connect to the database without a problem in Aqua Data Studio. Any ideas on this would be great.
Problem solved by reinstalling Sybase IQ drivers and updating to latest version of iAnywhere.Data.SQLAnywhere.

Accessing MySQL via C# program - ERROR [IM002] Data source name not found and no default driver specified

I'm debugging an old C# program that was designed to take in .dbf files, connect to a database (for some reason*), and then output those .dbf files in a more human-friendly, formatted manner (an Excel file). A released version of this program (years ago) works fine, but has some things that need ironing out. Hence, my attempts to debug the available Visual Studio Solution.
I'm having trouble with the connect to a database part, as the program returns the above error.
I'm not at all too experienced with MySQL, but I'll try to give all the details I can.
The program is being debugged in Visual Studio 2005. It was probably created there too, although some things look outdated. My OS is Windows 7, 32-bit.
I'm using MySQL version 3.23.42, and is installed on the very computer where the program is running. No network setups here, since the Database likely stores temporary data, and then outputs it to the Excel file.
I'm not sure if this is correct (ODBC? Instead of SQL?), but this is at the top of the program:
using System;
using System.Data;
using System.Data.Odbc;
using System.Windows.Forms;
I also had the MyODBC 3.51.05 installed.
Here's the connection string (note: I did not write this, it was already there):
string str_connection="DRIVER={MySQL ODBC 5.1 Driver};SERVER="localhost";DATABASE="TKCinterface";UID="ids";PASSWORD="ids";OPTION=3";
The program fails when it tries to open a connection, which I assume has something to do with the connection string.
My attempts to manually connect via Tools -> Connect To Database was met with failure, or at least the options I chose.
Data source: Microsoft ODBC Data Source
Data provider: .NET Framework Data Provider for ODBC
I don't see the database in the Window that follows.
I can open up MySQL via the Command line, and also see the database (TKCInterface), so I'm not sure what the problem is.
Curiously, there is nothing that references MySQL in the References of the project. The whole thing builds fine, though.
Any help on this would be much appreciated. Thanks.
Regards,
Zack_Falcon
Specify the port with which you are connecting to mysql
change the connection sting to
string str_connection="DRIVER={MySQL ODBC 5.1 Driver};SERVER="localhost";DATABASE="TKCinterface";UID="ids";PASSWORD="ids";Port=3306;";
Hope this helps
You definately need mysql.data and mysql.data.entity in your reference list.
Download the libaries from here http://dev.mysql.com/downloads/connector/net/

Categories