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();
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,543 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,383 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Sander van de Velde | MVP 30,551 Reputation points MVP
    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