Cannot connect to SQLlIte in .NET

Anonymous
2023-05-08T08:41:07.1933333+00:00

I placed sqllite file in App_Data the file name is logindb.

When I try to open the file it gives error

   // Create a new database connection:
            sqlite_conn = new SQLiteConnection("|DataDirectory|logindb");
            sqlite_conn.Open();
Developer technologies .NET Other
Developer technologies ASP.NET Other
{count} votes

1 answer

Sort by: Most helpful
  1. Sander van de Velde | MVP 36,761 Reputation points MVP Volunteer Moderator
    2023-05-08T21:18:24.96+00:00

    Hello @KALYANA ALLAM,

    in the constructor the connectionstring to the database file must be provided.

    The path you demonstrate does to seems to be a valid path, because of the pipe (|) characters.

    Try forward or backward slashes for a change.

    Next to that, I recommend testing if the file exists:

    string curFile = @"c:\temp\test.txt";
    Console.WriteLine(File.Exists(curFile) ? "File exists." : "File does not exist.");
    
    

    If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. All community members with similar issues will benefit by doing so. Your contribution is highly appreciated.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.