2

I have created a SQLite db. It is stored on the C: of my machine.

My application connects to the db ok when running in Local Host. However, when I deploy the Web App to Azure then it fails to connect the database.

I have installed the SQLite Nuget package. I have tested this in local host and it works.

Web Config Connection String:

<connectionStrings>
<add name="Testdb" connectionString="Data Source=C:\TestSQLite\Testdb.db;Version=3;" providerName="System.Data.SqlLite"/>
</connectionStrings>

Web Form Data Source:

<asp:SqlDataSource ID="Testdb" ConnectionString="<%$ ConnectionStrings:Testdb %>" ProviderName="System.Data.SQLite" SelectCommand="select * from BatchNumbers" runat="server">

I expect the web form to display information stored in the SQLite database table 'BatchNumbers'

And here is the Error Message:

[SQLiteException (0xe): unable to open database file]
   System.Data.SQLite.SQLite3.Open(String strFilename, String vfsName, SQLiteConnectionFlags connectionFlags, SQLiteOpenFlagsEnum openFlags, Int32 maxPoolSize, Boolean usePool) +644
   System.Data.SQLite.SQLiteConnection.Open() +5579
   HTML5OfflineApplication.BulkCopy_DataTableToSQLLite.Button1_Click(Object sender, EventArgs e) in C:\Users\Me\OneDrive - Me\Visual Studio\source\repos\Offline\Offline\Secure\BulkCopy_DataTableToSQLLite.aspx.cs:32
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +109
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +108
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +31
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3470

I have amended the connection string and tried the following:

sql_con = new SQLiteConnection(a, true);

and also

 connectionString="Data source=C:\TestSQLite\Testdb.db; Version=3; FailIfMissing=False"

I think my error is in the event args here which references a specific location on my device that isn't accessible to the program:

HTML5OfflineApplication.BulkCopy_DataTableToSQLLite.Button1_Click(Object sender, EventArgs e) in C:\Users\Me\OneDrive - Me\Visual Studio\source\repos\Offline\Offline\Secure\BulkCopy_DataTableToSQLLite.aspx.cs:32

Is it this that is causing the conflict?? Help!! Arggghe enter code here

2
  • Possible duplicate of Where to put SQLite database file in Azure App Service? Commented Jun 3, 2019 at 16:26
  • Hi thanks for this. I have read through the link and I cant see how it helps me. My DB file is on the user device. And my web app accesses data from that location. Seems to be a problem specific to the connection string and/or permissions. What I cant understand is why it works in local host but not live. Commented Jun 4, 2019 at 8:41

1 Answer 1

2

Regarding to your comment you want to store the database on the users PC - you cannot open files from the user device without the user actually uploading/selecting it explicitly. You need to either store a user-specific database on your server to access it in the code behind or use something client-side like the browsers localStorage with client-side JavaScript. Being able to access files on the users computer from a web application would be a huge security issue.

Another option would be creating a client-side application instead of a web application.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi thanks (or not !!! ha!) for the advice. Up to now I have focused on web apps. So I could create a windows app instead to manage the problem. Can you suggest a tutorial or learning resource - I have never built a windows app before.
If you want to create a native Windows app, have a look here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.