samedi 4 juillet 2015

Can't create connection to an sqlite DB

I've made a code that create the database automatically in the folder where the software is executed. The DB was created succesfull, but when I create the object for the connection this exception is displayed:

System.Data.SqlClient.SqlException (0x80131904): There was a network error or specific instance while trying to establish a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) ---> System.ComponentModel.Win32Exception (0x80004005): Can not find the file specified

on this line:

con.Open();

but the problem I think is on this declaration of the connection:

static SqlConnection con = new SqlConnection(
        "Server=localhost;Database=AppDB.sqlite;");

What am I doing wrong?

UPDATE Details:

 SqlCommand command = new SqlCommand(@"INSERT INTO Team (name,code, shortName, squadMarketValue, 
                crestUrl, link_self, link_fixtures, link_players, caption) VALUES (@name,
                @code,@shortName,@squadMarketValue,@crestUrl,@link_self,@link_fixtures,
                @link_players,@caption)", con);

How you can see I'm using parametizer query, and if I use this object:

static SQLiteConnection m_dbConnection = new SQLiteConnection("Data Source=SoccerForecast.sqlite;Version=3;");

the con variable is underlined in red, an the compilers tell me:

it is not possible to convert SqliteConnection in SqlConnection

Aucun commentaire:

Enregistrer un commentaire