I am trying to build my first .exe from a c# winforms project. I am using the Flexera Installing Shield. So far I can build and install it and it runs successfully on the same machine where I am developing. In this project I am using a local db. I can also install it on another machine, but as soon as I`m trying to access the Db via a button it complains. I think it has something to do with the connection string. At least it complains at the line where I am trying to access the Db with:
Error 26 - Error Locating Server/Instance Specified
Here is my obviously wrong connection string:
string connectionString = #"Data Source=(LocalDB)\v11.0;AttachDbFilename=""C:\Users\idiot\Documents\Visual Studio 2013\Projects\Vis\Vis\LocalDbVisTest.mdf"";Integrated Security=True";
Thank you for any help or hint in advance!
Instead of using an absolute path for your connection string, use
Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\LocalDbVisTest.mdf;Integrated Security=True
The reason your program cannot find the database is because it is looking in
C:\Users\idiot\Documents\Visual Studio 2013\Projects\Vis\Vis\LocalDbVisTest.mdf
Which, presumably, doesn't exist on your client's machine.
You can manually set your DataDirectory by using AppDomain.CurrentDomain.SetData("DataDirectory", path). You can get the path of your executable by using AppDomain.CurrentDomain.BaseDirectory
Related
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
I have a C# application which accesses a local auto-named database like DB_Users.mdf to pull out user connection details.
My connection string is:
Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\DB_Users.mdf;Integrated Security=True
When I deploy this application on a laptop, I get an error like this
The database"C:\ProgramFiles(x86)\ISTL\PCArchieSetup|DB_USEr.MDF" can't be opened because itis version 852 ,the Server support version 782 and earlier.Couldn't open new database "C:\programfiles\IstL\PcArchie\DB_users.mdf"Create database is aborted.An attempt to attach an auto-named database for file "C:\programfiles\IstL\PcArchie\DB_users.mdf" failed. A database with the same name exist or specific file cannot be opened on UNC share
Initially, I thought this VS version problem. So I updated to VS community 2015. But still getting the same error. I suspect the file location it's trying to access is the problem. But don't know how to resolve it. Can you share your thoughts on this? Thanks in advance for your help.
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
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/
I have a windows Application written at C Sharp, which is updating data store in SQL server 2008. When I am running application from .Net, I have no issues. I compiled application and install on the same laptop. When I run exe file I am getting the following error: "System.Data.SqlException (0x80131904): A network-related or instance-specific error occured while-establishing a connection to SQL Server. The server was not found or was not accessible".
Why I can connect to SQL server from MS Visual Studio, and not able to make connection to SQL from executable file (same laptop) ? Thank you.
Make sure the config file where your SQL connection string should be stored is next to the exe file when you install your application.
Please ensure that you have a file called "projectname.exe.config" right next to your exe. If so, then please ensure that you have the SQL connection string in this config file. If so, the please ensure that it is the correct connection string. Also, please ensure that the user account specified in the connection string has access to the DB. If you are using windows authentication (SSPI) then please ensure the your windows account has access to the DB.
NOTE: the config file name MUST be "exeName.exe.config". The exeName is usually the project name. Just in case you have changed the exe name from the default.
Hope this helps.