简体   繁体   中英

Error Data source name not found and no default driver specified with Odbc in ADO.NET

I'm having this error when i try to add some data from UI into MSSQL database and through all the questions&answers about this error i found, couldn't understand where the problem is. Could anyone give me some help? Thanks.

OdbcConnection conexiune = new OdbcConnection("Data Source=CODRINMA\\codrinma;Initial Catalog=BD;Integrated Security=True");
conexiune.Open();
OdbcCommand cominsert = new OdbcCommand("insert into Tabela(idX,denumire,adresa,idY) values(?,?,?,?)", conexiune);
cominsert.Parameters.Clear();
cominsert.Parameters.AddWithValue("@idX", int.Parse(txtID.Text.Trim()));
cominsert.Parameters.AddWithValue("@denumire", char.ToUpper(txtDenumire.Text.Trim()[0]) + txtDenumire.Text.Trim().Substring(1));
cominsert.Parameters.AddWithValue("@adresa", char.ToUpper(txtAdresa.Text.Trim()[0]) + txtAdresa.Text.Trim().Substring(1));
cominsert.Parameters.AddWithValue("@idY", int.Parse(cmbCamp.SelectedValue.ToString()));
cominsert.ExecuteNonQuery();
MessageBox.Show("Message!!");
conexiune.Close();
this.Dispose();

"An unhandled exception of type 'System.Data.Odbc.OdbcException' occurred in System.Data.dll

Additional information: ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"

When using ODBC you need to include the driver to use in the connection string.

See OdbcConnection.ConnectionString .

For instance if your server is SQL Server then add

driver={SQL Server}

to the connection string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM