File is encrypted or is not a database sqlite3 VB.NET - vb.net

My client/server application is written on VB.NET and it uses sqlite3 (*.db3) database. Everything was working fine with the old .db3 database unless I had to delete it and make a new one. I am using SQLite Maestro to create the database, import tables and data and that's it, but for some reason server won't read the database anymore saying that "file is encrypted or it's not a database file". Alright, what just happened? This is an old project from 2012, I remember all I did was just create the database in Maestro, add the tables and the data and it was all working like a charm. Now doesn't work doing exactly the same thing! I though that they changed something and Maestro is creating db's differently now, so I tried to use older version, but it's not possible to use older version of the program. I noticed that whenever I create a fresh database and attempt to use it with the server and every time it shows the error message that the file is encrypted or it's not a database then the database is corrupted. I can't open it in SQLite Maestro anymore. What should I do ?
Don't know if this matters, but here's the code that reads the database:
Private Shared ReadOnly connectionString As String = String.Format("Data Source={0};version=3;", ReadDatabasePath())
Private Shared connection_ As New SQLiteConnection(connectionString)
Public Shared ReadOnly Property Connection() As DbConnection
Get
Return connection_
End Get
End Property

Related

Can't access encrypted sqlite database

I used Navicat Premium to create the database file and selected encrypted to put a password. Now when I try accessing the database in my vb.net program I get an error saying...
file is encrypted or is not a database
"Data Source=\\10.10.10.10\Folder\database.db;Password=pwd;Version=3;", True
The above is my connection string (please ignore the network path =) ). Anyway, I can get through opening the connection but when reading data I get the error. I tried creating another database that doesn't have a password and it worked fine. I even copy pasted the password I have in code to navicat to make sure i typed it correctly.

Local Database: Not loading all the changes of the tables and views

I am using Visual Studio 2012 and an SQL Server Database.
At first, my program loads all the tables as well as views but when I try to do some modifications to the database schema (e.g. add some views) the changes are not reflected when I deleted the connection in the Solution Explorer-Model and then reconnect it.
I tried to delete the connection again, load the database and reconnect, but still, I get same results.
Why is this so? Any idea?
First, I make a database by clicking App_Data and add new Item. I add SQL Server Database. So that's why the entities has a .mdf extension.
Next, I add new tables on the database by right clicking the "Tables" and Add new Table on it. Insert new columns as well as the keys.
Then, I connect to the database by Right clicking Model in the Solution Explorer and add ADO.Net Entity Model. I used the Database.mdf for my connection. After that, it automatically generates the connection string in the web.config as well as the diagram.
Usually, when I made some changes in the database, I deleted the connection and reconnect again. Before I had no problems with it. The changes were seen upon reconnection but this time when I tried using with another app, I'm wondering why the modifications were not seen. I tried many times to connect and delete again the database but still nothing works.
As I understand you, you works directly with .mdf file. Consecuently, each time when you starts your application it copies into Debug folder and if you work with this local copy (it depends on your connection string in App.config) you change data exactly in Debug folder. So, each time you erase your changes when application starts, try to changes your connnection string.

Legacy VB6 Application Access To SQL Database Migration

My company has vb6 application with more than 100 forms. application was developed using VB6 and Access.
Now my company wants me to convert existing application from MS Access to SQL Server.
Application is using DAO to connect with Access. I've already convert Access Database to SQL With data.
Then I changed
Private db As Database
Set db = OpenDatabase(Access_File_Path, dbDriverComplete, False, ";pwd=access_password;")
to
Set db = OpenDatabase("", False, False, "odbc;dsn=Database_ODBC_Name")
All select,insert, update, delete queries works fine.
but I am getting error on such line
.Recordset.AddNew
.Recordset.Delete
.Recordset.Update
.Recordset.CancelUpdate
getting errors like
Runtime Error 3027 Cannot Update, Database or Object is read only
and
ODBC Error
Any solution or way to use existing code with SQL ?
As your error message say:
The database is read-only for one of these reasons:
You used the OpenDatabase method and opened the database for read-only access.
In Microsoft Visual Basic, you are using the Data control, and you set the ReadOnly property to True.
The database file is defined as read-only in the operating system or by your network.
The database file is stored on read-only media.
In a network environment, you do not have write privileges for the database file.
When working with a secured database, the database or one of its objects (such as a field or table) may be set to read-only. You may not have permission to access this data with your user name and password.
Close the database, resolve the read-only condition, and then reopen the file for read/write access.

Invalid value for attachdbfilename

I'm currently trying to distribute a application that relies on some form of database in .NET. I am trying to use SQL Server Express or SQL Server Express LocalDB.
For accessing the database I am using the entity framework.
Now the target is to create a deployable version that does not require any alterations on the SQL server by hand. It needs to install and setup as far as needed to launch the application. All goes well on my development computer. How ever once deploying to another computer the problems begin.
I tried the LocalDB in order to avoid the requirement to setup the database structure by hand on the target machine. How ever upon launching the application its reports a problem with the connection string. The attachdbfilename is not valid.
This filename is set to attachdbfilename=|DataDirectory|\database\Db.mdf
As I said. On my development maschine this works. Both when using the deployed files and when running it from the IDE. Yet the target mashine reports the problem. I installed the SQL Server Express 2012 LocalDB using ClickOnce along with my application. The deployed files contain the mdf file in the proper directory.
The full connection strings are:
<connectionStrings>
<add name="DbContainer" connectionString="metadata=res://*/database.DbModel.csdl|res://*/database.DbModel.ssdl|res://*/database.DbModel.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\database\Db.mdf;integrated security=True;connect timeout=30;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
I fail to see a reason why the attachdbfilename is not valid. The installation of the sql server on the target machine seems to be okay.
I also tried to pulish it with the normal SQL Server 2012 express. How ever I assume if I want to use this, without a attached database file I need to create the required database by hand. And that is not a option.
I read in some questions that this indicates a problem with the create ObjectContext but this one is looking good as well:
Public Partial Class DbContainer
Inherits ObjectContext
Public Sub New()
MyBase.New("name=DbContainer", "DbContainer")
MyBase.ContextOptions.LazyLoadingEnabled = true
OnContextCreated()
End Sub
Public Sub New(ByVal connectionString As String)
MyBase.New(connectionString, "DbContainer")
MyBase.ContextOptions.LazyLoadingEnabled = true
OnContextCreated()
End Sub
Public Sub New(ByVal connection As EntityConnection)
MyBase.New(connection, "DbContainer")
MyBase.ContextOptions.LazyLoadingEnabled = true
OnContextCreated()
End Sub
...
Just like it got generated by the entity framework.
I am running out of ideas on how to solve this problem.
Okay the problem turned out to be the |DataDirectory|
I replace this entry in the connection string by hand using the proper one click data directory I optained using:
Dim dataDir As String
If ApplicationDeployment.IsNetworkDeployed Then
Dim ad = ApplicationDeployment.CurrentDeployment
dataDir = ad.DataDirectory
Else
dataDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
End If
No problem loading the database file anymore. I can't say why the replacement of the |DataDirectory| is not working. For the version on the development computer this is simply replace with a empty string... and this works because the working directory is the parent of the refered database directory.
How ever when using ClickOnce the data files, including the database, is located in a different directory. This causes the connect string to fail. The code above fixes this problem. I can't explain for what reason this is not working out of the box.

How can I fix LINQ dependency issues with a VB.NET deployment?

I have a program that contains .dbml files. I created this file with Server Explorer.
I want to execute this program on other computers but I seem to be having issues with dependencies because I use LINQ.
How can I fix this?
Can you be more specific? What errors are you encountering? Did you use SQL Passwords or Network authentication? Do your users have network accounts added to SQL? Is this a permission based error?
Just one other possibility: Your users should have .NET 3.51 installed on their systems or they won't get the best possible Linq support. They might not have the Linq assemblies at all.
Yeah, we need more info, but I'm guessing you're having problems with the ConnectionString? as in, there's a connection string in your DBML designer file, and it doesn't match your production DB connection string?
If this is the case, then perhaps write a class that handles all instantiations of your DataContext in your code.
Then, within that class, whenever a new datacontext is created, you override the DBML connectionstring with your current connectionstring, probably from your web.config. this ensures your LINQ stuff is always connected to the correct DB during runtime.
Perhaps something like this (the property names might differ):
Public Shared Function GetNewContext() As YourDataContext
Dim dContext As YourDataContext
dContext = New YourDataContext()
dContext.Connection.ConnectionString = MyConnectionStringFromTheWebConfig()
Return dContext
End Function