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.
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.
I want to write to a .accdb file. When I test and do such from localhost it works w/o any issues. However if I try to write to it from my URL it errors. The .accdb is stored in a folder created from within VS called Database.
How should I set up/store the .accdb so I can write to it from the web?
Error message is
The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine.
Connetion String is
"Microsoft.Jet.OleDb.4.0;Data Source=|DataDirectory|Testing.accdb"
EDIT
if I change the connection string to 12.0 same error message
The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.
In Resposne To Comment
I am using VS2010 and do not have the option of in my options
In the bottom-left corner of the Options dialog, check the box that says, "Show all settings"
This is what I see under optionsenter image description here
What is your server operating system version?You may need to install Access software on your server.
And if your Access is x86,you need to specify the x86 mode to compile your project,instead of using anycpu mode.
You'd better use Microsoft.ACE.OLEDB.12.0,when your database is .accdb.
If not OK, you can try to download and install Microsoft Access Database Engine 2010 Redistributable: url(http://www.microsoft.com/en-us/download/details.aspx?id=13255) .
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 have two MDF files in a directory down the AppData/Local path. If I attempt to open them using LocalDb.
My connection string is of the form:
Data
Source=(localdb)\v11.0;AttachDbFilename="C:\Users\Anna\AppData\Local\CaseTrakker
Software\CTDynamoDisconnected\CTDynamoDisconnected_Data.mdf";Integrated
Security=True;Connect Timeout=10
I have a sample desktop application that attempts to connect to this MDF, and I get this exception:
System.Data.SqlClient.SqlException (0x80131904): Cannot open database
"C:\USERS\ANNA\APPDATA\LOCAL\CASETRAKKER
SOFTWARE\CTDYNAMODISCONNECTED\CTDYNAMODISCONNECTED_DATA.MDF" requested
by the login. The login failed. Login failed for user 'IMA\Anna'.
If I move this file to any other location, or rename it (even to a name that is longer), I am able to connect to it.
There appears to be something peculiar about this location or something.
One other odd thing: it worked last week. So far as I am aware, nothing has changed on my machine or my Domain Security.
I'm at a complete loss as to what else to even try. Ideas?
Can you check if there is anything interesting in the LocalDB instance log file? It is located by default in %localappdata%\Microsoft\Microsoft SQL Server Local DB\Instances\v11.0 folder.
One cause of this problem is if you go into your C:\Users\[username] folder and delete the MDF and LDF files. If you do this, then that's akin to doing the same thing to full-blown SQL Server. The server instance still thinks it has the databases but they're obviously not going to work.
A work-around to the problem is to change the database name in your connection string and it should just work.
To actually fix the problem, open up SQL Management Studio, connect to server (LocalDb)\v11.0 (likely with Windows Authentication) and you can detach these databases this way.
In my case I had that DB for a while and mistakenly deleted its MDF and LDF files.
To solve this, I opened SQL Management Studio and connected to (localdb)\MSSQLLocalDB using Windows Authentication then created manually a new empty DB with desired name like that in web.config connection string
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=myDb;Integrated Security=True;" providerName="System.Data.SqlClient" />