i face problem when i try create sqlite database with password.
When I create database without password it is work very good but if i try to set password it give me error message "Could not load file or assembly 'System.Data.SQLite.SEE.License, Version=1.0.117.0, Culture=neutral, PublicKeyToken=433d9874d0bb98c5' or one of its dependencies. The system cannot find the file specified.".
My Code :
My Code Is :
Imports System.Data.SQLite
Imports System.IO
Public Class Form1
Dim DB_Path As String = Application.StartupPath & "\DB\database.sqlite"
Private Async Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
If File.Exists(DB_Path) = False Then
' create db folder if not exist
If Not (System.IO.Directory.Exists(Application.StartupPath & "\DB\")) Then
System.IO.Directory.CreateDirectory(Application.StartupPath & "\DB\")
End If
' Create a new SQLite connection
Using conn As New SQLiteConnection("Data Source=" & Application.StartupPath & "\DB\database.sqlite" & ";Version=3;")
'set db password
conn.SetPassword("ashraf123") ' the error here
'change db conn string
conn.ConnectionString = "Data Source=" & DB_Path & ";Password=ashraf123;Version=3;"
'open conn
Await conn.OpenAsync
' do somthing
End Using
Else
Using conn As New SQLiteConnection("Data Source=" & DB_Path & ";Password=ashraf123;Version=3;")
Await conn.OpenAsync
' do somthing
End Using
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
End Class
I tried that change platform from any cpu to x86.
I tried that change platform from any cpu to x64.
I tried that Copy system.data.sqlite.dll and all other .dll files to startup app folder.
I tried uninstall all packages and reinstalled them again.
i tried creat new project and do all mentioned steps.
install this package SQLitePCLRaw.bundle_e_sqlcipher
and use the password in connection string like this :
Data Source=" & DB_Path & ";Password=ashraf123
Related
I am working on created a login form for an application I am working on. I have my application set up to properly connect to the database and run stored procedures and queries on the database as well.
However I am unsure how to send messages from the database to my VB.Net Application. Right now I have essentially two methods that execute code for my database:
Public Function ExecuteCMD(ByRef CMD As SqlCommand) As DataTable
Dim DS As New DataSet()
Try
OpenDBConnection()
CMD.Connection = DB_CONNECTION
If CMD.CommandText.Contains(" ") Then
CMD.CommandType = CommandType.Text
Else
CMD.CommandType = CommandType.StoredProcedure
End If
Dim adapter As New SqlDataAdapter(CMD)
adapter.SelectCommand.CommandTimeout = 300
adapter.Fill(DS)
Catch ex As Exception
Throw New Exception("Database Error: " & ex.Message)
Finally
CloseDBConnection()
End Try
Return DS.Tables(0)
End Function
Public Function ExecuteCMDWithReturnValue(ByRef CMD As SqlCommand) As Boolean
Try
OpenDBConnection()
CMD.Connection = DB_CONNECTION
CMD.Parameters.Add("#ret", SqlDbType.Int).Direction = ParameterDirection.ReturnValue
CMD.CommandType = CommandType.StoredProcedure
CMD.ExecuteNonQuery()
Dim result As Object = CMD.Parameters("#ret").Value
Return If(Convert.ToInt32(result) = 1, False, True)
Catch ex As Exception
Throw New Exception("Database Error: " & ex.Message)
Return False
Finally
CloseDBConnection()
End Try
End Function
These functions honestly work fine, but they are horrible for error processing.
For example I'd like to be able to set up my Store Procedure for logging in to the application to return a "Username not found" or "Password incorrect" message so that I can display to my user exactly what the problem is, as opposed to just returning a generic "Login information incorrect" message from only returning true or false on the logging in going through or not.
I unfortunately do not know exactly how to do this on either end. I don't know what to set up on the SQL Server side to have it spit out messages in procedures, and I don't know hot to receive those messages in VB.Net.
You can verify your user right in VB. I don't think it is a good idea to tell the user If the password or user name is wrong (or if both are wrong). If this data is password protected then it should be protected from malicious logins. It would help a hacker to know what was wrong.
Private Function VerifyPassword(pword As String, uname As String) As Boolean
Using cn As New SqlConnection(My.Settings.UsersConnectionString)
Dim cmd As New SqlCommand("Select Count(*) From Users Where UserName = #UserName And UserPassword = #Password;", cn)
cmd.Parameters.Add("#UserName", SqlDbType.VarChar, 100).Value = uname
cmd.Parameters.Add("#Password", SqlDbType.VarChar, 100).Value = pword
Try
cn.Open()
Dim i As Integer = CInt(cmd.ExecuteScalar())
If i > 0 Then Return True
Return False
Catch ex As Exception
Throw
Finally
cn.Close()
cmd.Dispose()
End Try
End Using
End Function
Of course the password is stored hashed with a salt.
I want to change my .mdb Database password by C# code. I am using following code for this but some error comes. So please help me.
IErrorInfo.GetDescription failed with E_FAIL(0x80004005). This error comes.
Code:
OleDbConnection cnn1 = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Jet OLEDB:Database Password=" + pwd + ";Mode=Share Exclusive");
OleDbCommand cmd1 = new OleDbCommand();
cnn1.Open();
cmd1.Connection = cnn1;
string Query="ALTER DATABASE PASSWORD <newPassword> " + pwd + "";
cmd1.CommandText = Query;
blnSuccess = cmd1.ExecuteNonQuery();
In the Last finally i got the answer of my Question.
Following code is help me for change the .mdb Database Password change by C# Code.
Add a reference to Microsoft DAO 3.6 Object Library
using DAO;
public void ChangePassword(string sDBPath, string sDBPasswordOld, string sDBPasswordNew)
{
dao.DBEngine dbEngine;
dao.Database db;
db = dbEngine.OpenDatabase(sDBPath, true, false, ";PWD=" + sDBPasswordOld);
db.NewPassword(sDBPasswordOld, sDBPasswordNew);
}
Thanks for the help in advance
I am using access 2013 with a wpf vb.net app at the moment I have
Public sConnstring As String
Function Conn_DB1()
'<<<<<<<<<<<<<< This is for Data Base 1 >>>>>>>>>>>>>>>
sConnstring = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source= " & My.Settings.DatastoreLocation & "\ACCDB\DB1.accdb; Persist Security Info=False;"
Return sConnstring
End Function
However as I want to password protect the database if I use the old
sConnstring = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source= " & My.Settings.DatastoreLocation & "\ACCDB\DB1.accdb; Jet OLEDB:Database Password=MyDbPassword;
I can not seem to get it to connect I get the error
"Cannot Open Database - It may not be that the database that your application recognizes, or that the file may be corrupt"
Any Ideas as to why this may be happening?
Cheers
I have a problem while trying to copy my project folder to another hard drive. My project in Visual Studio is defined in h:\ and while run exe file project no any problem but while copy folder project to another hard drive I have a problem to connect the application to SQL Server.
See these screenshots:
http://upload.tehran98.com/img1/f9kio8ssjofg1lhkjdg.jpg
http://upload.tehran98.com/img1/k6ajdb22xhdjrgcn419.jpg
For example in login form and in login button my code is:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim conn As New SqlConnection("Server=.\SQLExpress;AttachDbFilename=" + Environment.CurrentDirectory + "\Database\Automation.mdf;Database=Automation;Trusted_Connection=Yes;")
s2 = "Select count( * ) from Login where UserName = '" & TextBox1.Text & "' and Password = '" & TextBox2.Text & "'"
Dim com As New SqlCommand(s2, conn)
Dim res As Object
conn.Open()
res = com.ExecuteScalar()
conn.Close()
If res = 1 Then
MsgBox("Welcome Dear " + TextBox1.Text, MsgBoxStyle.OkOnly, "Login Successful")
us = TextBox1.Text
If us = "admin" Then
Main.Label4.Text = "ADMINISTRATOR"
Else
Main.Label4.Text = "USER"
us = TextBox1.Text
Main.Button3.Enabled = False
Main.Button5.Enabled = False
Main.Button9.Enabled = False
End If
Main.Show()
Me.Hide()
Else
MsgBox("Invalid User OR Password", MsgBoxStyle.Critical, "Attention Please")
TextBox1.Text = ""
TextBox2.Text = ""
Exit Sub
End If
End Sub
You need to specify where the database is, you can't use Environment.CurrentDirectory. CurrentDirectory uses the path of the current working directory. So either move the database to the same hard drive or change the path to your database.
http://msdn.microsoft.com/en-us/library/system.environment.currentdirectory.aspx
I was going to check if my database is connecting to my project in vb.net, but it's seems like there's a problem on my code or to my SQL server. It always shows me a message "Login failed for user 'id/id2'".
Here is my code:
Imports System.Data.SqlClient
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sqlconn As New SqlConnection
sqlconn.ConnectionString = "server = (local);Database=OJT;integrated security=true"
Try
sqlconn.Open()
Catch ex As Exception
MessageBox.Show(ex.Message, "Connection to Sql Server Failed!", MessageBoxButtons.OK)
End Try
Me.Text = "You are successfully connected to Sql Server"
End Sub
End Class
try this one instead :
"Data Source=(local);Initial Catalog=OJT;Persist Security Info=True;User ID=(Your User ID);Password=(Your Password)"
hopes that it solve your problem. Good Day!
try this
sqlconn.ConnectionString = "Data Source=(local);Initial Catalog=OJT;Integrated Security=True"