I am trying to setup entity framework with sqlite in visual studio 2012. So, here is what I have done so far:
Installed System.Data.Sqlite with "Design-Time Component".
Entity Framework Tools for visual studio 2012.
System.Data.SQLite,System.Data.SQLite.EF6 and System.Data.SQLite.Linq from NuGet.
Now I am trying to add "ADO.net Entity Data Model",By following steps:
Add New Item.
ADO.net Entity Data Model.
"EF Designer from Database" from wizard and click "Next".
Add "New Connection", Data Source: System.Data.Sqlite Database File.
After choosing db file and provide password when I click on "Next" button, following error occurs:
I have checked my db file in "Sqlite Browser" also I have setup password for db file with the help of following code:
string conn = #"Data Source=pahtto\App_Data\app_data.sqlite;";
SQLiteConnection connection = new SQLiteConnection(conn);
connection.SetPassword("123456");
connection.Close();
What am I missing?
Please guide me.
Thank you.
Try looking in your App.config file and change the connection string and set your password there.
old connection string
source=X:projectsmeowdb.sqlite;
modified Connections string
source=X:projectsmeowdb.sqlite;password=this is my password
Look at this link for more information
http://www.dxsdata.com/2013/09/visual-studio-with-sqlite-solving-error-file-is-encrypted-or-not-a-database/
It seems that the problem was in my db file even though it was working fine in "Sqlite Browser".
So, I just deleted and created new file and every thing works.
Related
I am using Firebird database and newly started with this database so I am implementing with Visual studio 2015. I am accessing a Firebird Embedded database using ADO.NET and my Firebird Embedded database file extension is .CMP. I am successfully using ADO.NET.
Now I want to use with Firebird Entity Framework. I have done a successful install. When I click entity data model and select the Firebird data source it opens connection properties where I select server type =1(embedded).
This is my ADO.NET connection string:
string Connectionstring = "User=SYSDBA;Password=masterkey;Database=localhost:G\\CLINEDB.CMP;DataSource=localhost;Port=3050;Dialect=3; Charset=NONE;Role=;Connection lifetime=15;Pooling=true; MinPoolSize=0;MaxPoolSize=50;Packet Size=8192;ServerType=1;"
When I click test connection it show this error:
Unable to load DLL fbembed: the specified module could not be found
I have downloaded the embedded folder from Firebird and added it to the project solution so in advance option added 'Client Library as fbclient.dll file from project solution' for this I am getting error
Connection lost to database
How can I fix this?
I'm using Entity Framework's Code-First and LocalDB, with the following connection string:
Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=MyApp;Integrated Security=True;
Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;
ApplicationIntent=ReadWrite;MultiSubnetFailover=False;MultipleActiveResultSets=true;
The instance and its database files were properly created inside this path:
C:\Users\Me\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\MSSQLLocalDB
But I was messing around and I renamed then deleted the MSSQLLocalDB through Visual Studio's "SQL Server Object Explorer" and its files. Now that I created it back, all databases generated via EF Code First are being created inside my %USERPROFILE% folder, i.e. C:\Users\Me.
In "SQL Server Object Explorer", if I right click and "Add New Database", it shows the right path. Right clicking the instance then properties shows that "Default Database Location" is correct.
The registry is correctly configured:
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Microsoft SQL Server\UserInstances\{9F44D466-A9BA-40E3-9DEA-21E0638C80A2}]
...
"DataDirectory"="C:\\Users\\Me\\AppData\\Local\\Microsoft\\Microsoft SQL Server Local DB\\Instances\\MSSQLLocalDB"
I tried to create a new instance through SqlLocalDB Utility with a different name, but it behaves the same way. Also tried rebooting, before and after deleting the instance, no success.
I also tried reinstalling. I uninstalled Visual Studio (Web and Desktop), MS Data Tools, MSSQL Compact and MS LocalDB, then reinstalled VS, but no success.
I don't want to change my connection string and point it to the correct path, since the project is shared and maintained by other developers.
How do I revert this behavior? I'm using Visual Studio 2015 Express.
You can set the path here (in registry):
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Microsoft SQL Server\UserInstances]
The path is not a part of your connection string, so do you really have a problem?
We are working on an MVC application, I added the connection string and generated the data models. When I update the model from database in the .edmx file it updates the web.config file and I check it in TFS. When other other people get latest version from TFS, they see the connection but when they go to the .edmx file it has update the model from database grayed out? is there any way to fix this?
First, make sure your colleagues are opening the project which in source control in VS, not the local one.
Another thing is going into the workspace and change the local path not containing '#' character. More detail info about this, please take a look at this thread: Entity Framework Unable to refresh database tables under TFS 2010
When using the Add Controller helper/scaffolder with Entity Framework CRUD integration, I get the following error:
Unable to retrieve metadata for 'MyApp.Models.MyModel'. Cannot attach the file
'C:\Users\Lev\AppData\Local\Temp\2d7daf19-d47f-df24-ac76-d3df4fg2sa\aspnet-MyApp-
20130409170533.mdf' as database 'aspnet-MyApp-20130409170533.mdf'.
The question is: Why is it looking for the database in my temp files? The database file is located in:
C:\Projects\MyApp\MyApp\App_Data
This is my connection string:
Data Source=(LocalDb)\v11.0;
Initial Catalog=aspnet-MyApp-20130409170533;
Integrated Security=SSPI;
AttachDBFilename=|DataDirectory|\aspnet-MyApp-20130409170533.mdf
And so it seems that the reference to |DataDirectory| is misbehaving. How can I set DataDirectory?
If I manually put the correct path into the AttachDBFilename property, then the scaffolding works. But I'd still love to leave it as |DataDirectory|.
Just restart the Visual Studio. This helped at my project.
I went through MSDN pages to learn ADO.Net using Commands. I am able to read using the sample code posted there.
But when I tried to use the modification code below, the insert is not happening. I am not ale to figure out why. Can someone please tell me what is wrong with this code?
string connectionString = "A_VALID_CONNECTION_STRING";
string commandText =
"INSERT INTO Contacts (FullName, Mobile) VALUES ('Pierce Brosnan', '1800-007')";
SqlConnection connection = new SqlConnection(connectionString);
try
{
connection.Open();
SqlCommand command = new SqlCommand(commandText, connection);
Console.WriteLine(command.ExecuteNonQuery());
connection.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Edit
No exception is thrown.
The ExecuteNonQuery() which is supposed to return the no. of rows affected is returning 1.
Environment: Visual C# 2010 Express | SQL Server 2008 Express | Windows 7 Ultimate 32-bit.
Update
Previously I was using a MDF file present in the project. It was, I guess, automatically attached to the SQL server instance each time the project ran. This is when I had the problem. The connection string had some info about attaching a database file.
I removed the SQL Server 2008 Express that I installed along with Visual C# 2010 Express. Also removed the MDF file from the project.
I Separately downloaded and installed SQL Server 2008 Express along with Management Studio Express.
Created a new database in management studio.
Used a different type of connection string to use the database in the server.
Now INSERT is working!
P.S. I guess I should have mentioned that I had an attach database file scenario. Really sorry for that.
My suspicion is that you had the following scenario:
Database.mdf file was present in the project with the table structure created in it
Your connection string looked something like this Server=.\SQLExpress;AttachDbFilename=database.mdf;Database=dbname; Trusted_Connection=Yes;, i.e. loading the database in the connection string.
What was happening was, when you built/ran your project, your application was compiled and the database.mdf file was copied along with it to ApplicationProjectFolder\bin\Debug, so that when the application was run, the file database.mdf was present. This means that everytime you ran your project, the "empty" database.mdf file was copied from ApplicationProjectFolder\database.mdf to ApplicationProjectFolder\bin\Debug\database.mdf, hence the data "disappearing". Also, the file database.mdf probably had "Copy Always" set on its properties in the project.
So, the "INSERT" was working, it was just being "reset" everytime you ran your application.