Click here to Skip to main content
15,888,579 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Add unsubscribe link to header of the mail sent from outlook Pin
srikrishnathanthri12-May-16 2:38
srikrishnathanthri12-May-16 2:38 
GeneralRe: Add unsubscribe link to header of the mail sent from outlook Pin
Richard Deeming12-May-16 3:12
mveRichard Deeming12-May-16 3:12 
GeneralRe: Add unsubscribe link to header of the mail sent from outlook Pin
srikrishnathanthri12-May-16 3:23
srikrishnathanthri12-May-16 3:23 
QuestionSaving data with data-bound Form Controls Pin
Raabi Anony11-May-16 16:31
Raabi Anony11-May-16 16:31 
AnswerRe: Saving data with data-bound Form Controls Pin
Dave Kreskowiak12-May-16 1:15
mveDave Kreskowiak12-May-16 1:15 
GeneralRe: Saving data with data-bound Form Controls Pin
Raabi Anony12-May-16 16:48
Raabi Anony12-May-16 16:48 
QuestionThe ADO.NET provider with invariant name 'System.Data.SqlLite.EF6' is either not registered in the machine or application config file, Pin
jkirkerx10-May-16 14:16
professionaljkirkerx10-May-16 14:16 
Answer[100% Solved], How to get SQLite to work with vb.net and EF6 using the NuGet Package System.Data.SQLite (x86/x64) Pin
jkirkerx11-May-16 9:54
professionaljkirkerx11-May-16 9:54 
Well first off, SQLite doesn't support automatic database creation, you have to manually create the database. So I added that add-in to my Firefox and created the database.

I'm wondering if this is worth the time. This program uses old Dbase IV or Foxpro database files, and I wanted to use something faster and more modern for a new program feature that stores all the emails sent in the database, so if one fails it can be resent.

This kicked my butt, but I don't get an error anymore. I couldn't figure out the App.Config part the way the bulk of examples showed, but I did figure out how to point the database to a network drive via code in the Application, and pass it to EF6 DAL.

So in case your looking for an example of how to point SQLite to a network drive without hard coding the path, this is it, well I think it is, until something better comes along.

I apologize in advance for this being in VB. All the examples where in C#

My project has 3 modules, because it's getting too large in size.
Main Project EXE
Data Access Layer DLL
Entity DLL

I went back and stripped out the SQLite from the main project and Entity DLL and just installed it in the DAL DLL. Then just made references for SQLite back to the DAL. Then stripped out the SQLite and EF stuff in the App.Configs of DLL's

So in the DBContext class in my DAL, I added the conn string to use in New()
Public Class ameContext
  Inherits DbContext

  <ObsoleteAttribute("The default connection factory should be set in the config file or using the DbConfiguration class. (See <a href="http://go.microsoft.com/fwlink/?LinkId=260883">http://go.microsoft.com/fwlink/?LinkId=260883</a>)")>
  Public Shared Property DefaultConnectionFactory As IDbConnectionFactory

  Public Sub New(ByVal conString As String) '<< I added the conn string to use

      MyBase.New(conString)
      'SQLite doesn't support auto database creation 
      Entity.Database.SetInitializer(Of ameContext)(Nothing)

  End Sub
End NameSpace
Then I added a SQLiteConfiguration File to my DAL Class, which gets called from the DBContext above.
Imports System.Data.SQLite
Imports System.Data.SQLite.EF6

Imports System.Linq
Imports System.Text
Imports System.Data.Entity.Core.Common
Imports AccountMate_DAL

Namespace System.Data.SQLite.Entity

    Public Class SQLiteConfiguration
        Inherits DbConfiguration

        Public Sub New()

            SetProviderFactory("System.Data.SQLite", SQLiteFactory.Instance)
            SetProviderFactory("System.Data.SQLite.EF6", SQLiteProviderFactory.Instance)
            SetProviderServices("System.Data.SQLite", CType(SQLiteProviderFactory.Instance.GetService(GetType(DbProviderServices)), DbProviderServices))

        End Sub
    End Class
End NameSpace
And added a SQLiteConnectionFactory Class to my DAL Class, which gets called from the DBConfiguration above.
Imports System.Data.Common
Imports System.Data.Entity.Infrastructure
Imports System.Data.SQLite

Public Class SQLiteConnectionFactory
    Implements IDbConnectionFactory

    Public Function CreateConnection(ByVal connectionString As String) As DbConnection Implements IDbConnectionFactory.CreateConnection

        Return New SQLiteConnection(connectionString)

    End Function

End Class
The App.Config for the VB App, All I did was declare the DefaultConnectionfactory, which is the name of my DAL.
<entityFramework>
    <defaultConnectionFactory type="AccountMate_DAL.SQLiteConnectionFactory, AccountMate_DAL" />
  </entityFramework>  
Finally in the program, when initializing the context, I added the connstring, connstring is that string that was in the App.Config of the vb.net app shown below, higlighted in blue. Get the string and then delete it.
<add name="SQLiteConnection" connectionString="data source=d:\Amp\SIS\AMExtras.sqlite" providerName="System.Data.SqlLite.EF6" />
Dim context = new ameContext(connstring)

Hope that helps, like I said it was pretty confusing to figure out. And the examples were so basic and assumed it works.

[edit] 05//11/2013
Had no modify the DBContext to stop Database Creation
But I wrote a record to it, and updated the record 5 times now.

Be cool if I can figure out a way to detect the whether its using SQL Server or SQLite in the DBContext.

modified 13-May-16 11:08am.

QuestionHow we can get last 12 months using current month using sql Pin
MANISHA SONAWANE9-May-16 20:39
MANISHA SONAWANE9-May-16 20:39 
AnswerRe: How we can get last 12 months using current month using sql Pin
Mycroft Holmes9-May-16 21:37
professionalMycroft Holmes9-May-16 21:37 
GeneralRe: How we can get last 12 months using current month using sql Pin
MANISHA SONAWANE10-May-16 0:02
MANISHA SONAWANE10-May-16 0:02 
GeneralRe: How we can get last 12 months using current month using sql Pin
Mycroft Holmes10-May-16 0:12
professionalMycroft Holmes10-May-16 0:12 
AnswerRe: How we can get last 12 months using current month using sql Pin
CHill6010-May-16 22:22
mveCHill6010-May-16 22:22 
SuggestionRe: How we can get last 12 months using current month using sql Pin
Richard Deeming11-May-16 1:23
mveRichard Deeming11-May-16 1:23 
GeneralRe: How we can get last 12 months using current month using sql Pin
CHill6011-May-16 2:08
mveCHill6011-May-16 2:08 
GeneralRe: How we can get last 12 months using current month using sql Pin
Mycroft Holmes11-May-16 2:51
professionalMycroft Holmes11-May-16 2:51 
GeneralWe want only required Month and Year instead of complete date in where condition using sql Pin
MANISHA SONAWANE16-May-16 0:05
MANISHA SONAWANE16-May-16 0:05 
QuestionDisplay status of SQL query in VBA Pin
Member 124051985-May-16 4:57
Member 124051985-May-16 4:57 
AnswerRe: Display status of SQL query in VBA Pin
Dave Kreskowiak5-May-16 12:25
mveDave Kreskowiak5-May-16 12:25 
AnswerRe: Display status of SQL query in VBA Pin
Mycroft Holmes8-May-16 14:21
professionalMycroft Holmes8-May-16 14:21 
GeneralRe: Display status of SQL query in VBA Pin
Member 124051989-May-16 4:39
Member 124051989-May-16 4:39 
GeneralRe: Display status of SQL query in VBA Pin
Dave Kreskowiak9-May-16 4:50
mveDave Kreskowiak9-May-16 4:50 
AnswerRe: Display status of SQL query in VBA Pin
Sascha Lefèvre9-May-16 5:28
professionalSascha Lefèvre9-May-16 5:28 
AnswerRe: Display status of SQL query in VBA Pin
Patrice T9-May-16 5:42
mvePatrice T9-May-16 5:42 
GeneralRe: Display status of SQL query in VBA Pin
Member 124051989-May-16 8:52
Member 124051989-May-16 8:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.