|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Jan 2007
Città: villa verucchio
Messaggi: 1921
|
[C#] Problema con ADO.net
ciao, da poco mi sto interessando ai database e ADO.Net, però ho problemi nelle prime prove, sia su codice scritto da me, sia su codice esempio.
Vi incollo il pezzo: static void Main(string[] args) { SqlConnectionStringBuilder bd = new SqlConnectionStringBuilder(); bd.DataSource = "localhost"; bd.InitialCatalog = "Northwind"; bd.IntegratedSecurity = true; SqlConnection conn = new SqlConnection(bd.ConnectionString); try { conn.Open(); SqlCommand com = new SqlCommand("SELECT * FROM Products"); SqlDataReader reader = com.ExecuteReader(); ........ Quando l'esecuzione arriva al codice in rosso, si apre la shell e non accade nient'altro, devo chiuderla. Nel blocco catch non ci entra...qual'è la causa secondo voi? Grazie. EDIT: mi correggo, dopo una decina di secondi entra nel catch dandomi il seguente messaggio di errore: “A network-related or instance-specific error occurred while establishing 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> Il database in questione è nella cartella del progetto
__________________
CPU: Amd Phenom II 955--MB: Gigabyte GA-890GPA-UD3H--RAM:4 GB DDR3--SV: ATI Radeon HD 5770--HD: Western Digital Caviar Black 500 gb--ALI:: Corsair 650w--MONITOR: SyncMaster P2270--ROUTER: Netgear DG834G--SO: Win 7 Professional 64 bit Ultima modifica di mto89 : 03-08-2010 alle 09:34. |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Sep 2004
Messaggi: 3967
|
Che tipo di database è ?
__________________
Dai wafer di silicio nasce: LoHacker... il primo biscotto Geek
|
|
|
|
|
|
#3 |
|
Senior Member
Iscritto dal: Jan 2007
Città: villa verucchio
Messaggi: 1921
|
Microsoft office access database
__________________
CPU: Amd Phenom II 955--MB: Gigabyte GA-890GPA-UD3H--RAM:4 GB DDR3--SV: ATI Radeon HD 5770--HD: Western Digital Caviar Black 500 gb--ALI:: Corsair 650w--MONITOR: SyncMaster P2270--ROUTER: Netgear DG834G--SO: Win 7 Professional 64 bit |
|
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: Sep 2004
Messaggi: 3967
|
Ecco, quindi l'errore che ti da è giusto. Probabilmente hai settato dei parametri nella tua stringa di connessione per collegarti ad un db sql server.
Posta un pò la stringa
__________________
Dai wafer di silicio nasce: LoHacker... il primo biscotto Geek
|
|
|
|
|
|
#5 | |
|
Senior Member
Iscritto dal: Jun 2010
Città: Varese
Messaggi: 996
|
Quote:
Ora non ricordo C#*l ho usato mesi e mesi fa però la sintassi era diversa per un DB Access (se usi Visual Studio puoi collegarlo tramite Wizard anche...) |
|
|
|
|
|
|
#6 | |
|
Senior Member
Iscritto dal: Sep 2004
Messaggi: 3967
|
Quote:
Codice:
"Provider=Microsoft.Jet.OLEDB.4.0;Data source=PercorsoAlTuoDatabase.mdb"
__________________
Dai wafer di silicio nasce: LoHacker... il primo biscotto Geek
|
|
|
|
|
|
|
#7 |
|
Senior Member
Iscritto dal: Jan 2007
Città: villa verucchio
Messaggi: 1921
|
Giusto grazie della dritta, quindi detto in parole povere la connessione OLEdb è usata per i database in formato originario di Access, mentre SQLConnection per i tipi di database MySql? Che differenze sostanziali ci sono?
__________________
CPU: Amd Phenom II 955--MB: Gigabyte GA-890GPA-UD3H--RAM:4 GB DDR3--SV: ATI Radeon HD 5770--HD: Western Digital Caviar Black 500 gb--ALI:: Corsair 650w--MONITOR: SyncMaster P2270--ROUTER: Netgear DG834G--SO: Win 7 Professional 64 bit |
|
|
|
|
|
#8 |
|
Senior Member
Iscritto dal: Jan 2007
Città: villa verucchio
Messaggi: 1921
|
Ora ho scritto:
static void Main(string[] args) { OleDbConnectionStringBuilder bd = new OleDbConnectionStringBuilder(); bd.DataSource = "Northwind.mdb"; bd.Provider = "Provider=Microsoft.Jet.OLEDB.4.0"; OleDbConnection conn = new OleDbConnection(bd.ConnectionString); try { conn.Open(); OleDbCommand cmd = new OleDbCommand("SELECT * FROM Products"); OleDbDataReader reader = cmd.ExecuteReader(); try { while (reader.Read()) { .... .... e mi dà ancora errore sulla riga in rosso: "The 'Provider=Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine." In giro ho letto che può essere a causa dell'eseczione a 64 bit, ma il cpu target è x86, inoltre anche su una macchina con architettura e SO a 32 bit mi dà lo stesso errore, avete idea del perchè?
__________________
CPU: Amd Phenom II 955--MB: Gigabyte GA-890GPA-UD3H--RAM:4 GB DDR3--SV: ATI Radeon HD 5770--HD: Western Digital Caviar Black 500 gb--ALI:: Corsair 650w--MONITOR: SyncMaster P2270--ROUTER: Netgear DG834G--SO: Win 7 Professional 64 bit |
|
|
|
|
|
#9 |
|
Senior Member
Iscritto dal: Sep 2004
Messaggi: 3967
|
che reference hai linkate al progetto ?
Se non la hai già, credo ti serva solo aggiungere: System.Data Edit: e anche System.Data.Oledb;
__________________
Dai wafer di silicio nasce: LoHacker... il primo biscotto Geek
Ultima modifica di RaouL_BennetH : 03-08-2010 alle 15:17. |
|
|
|
|
|
#10 | |
|
Senior Member
Iscritto dal: Jun 2010
Città: Varese
Messaggi: 996
|
Quote:
|
|
|
|
|
|
|
#11 |
|
Senior Member
Iscritto dal: Jan 2007
Città: villa verucchio
Messaggi: 1921
|
No erano già presenti entrambi, ma anche su macchine diverse mi da stesso errore..
Voi scrivereste diversamente per accedere al database?
__________________
CPU: Amd Phenom II 955--MB: Gigabyte GA-890GPA-UD3H--RAM:4 GB DDR3--SV: ATI Radeon HD 5770--HD: Western Digital Caviar Black 500 gb--ALI:: Corsair 650w--MONITOR: SyncMaster P2270--ROUTER: Netgear DG834G--SO: Win 7 Professional 64 bit |
|
|
|
|
|
#12 | |
|
Senior Member
Iscritto dal: Jun 2010
Città: Varese
Messaggi: 996
|
Quote:
Non so come sia, non la guardo da qualche mese ... (ma tanti mesi :P) |
|
|
|
|
|
|
#13 |
|
Senior Member
Iscritto dal: Jan 2007
Città: villa verucchio
Messaggi: 1921
|
Non venendone a capo ho aggirato il problema usando il wizard di visual studio
__________________
CPU: Amd Phenom II 955--MB: Gigabyte GA-890GPA-UD3H--RAM:4 GB DDR3--SV: ATI Radeon HD 5770--HD: Western Digital Caviar Black 500 gb--ALI:: Corsair 650w--MONITOR: SyncMaster P2270--ROUTER: Netgear DG834G--SO: Win 7 Professional 64 bit |
|
|
|
|
|
#14 |
|
Senior Member
Iscritto dal: Jan 2007
Città: villa verucchio
Messaggi: 1921
|
Pensavo a chissà quali errori particolari invece si trattava solo del provider= che non ci va
OleDbConnectionStringBuilder bd = new OleDbConnectionStringBuilder(); bd.DataSource = "Northwind.mdb"; bd.Provider = "Provider=Microsoft.Jet.OLEDB.4.0";
__________________
CPU: Amd Phenom II 955--MB: Gigabyte GA-890GPA-UD3H--RAM:4 GB DDR3--SV: ATI Radeon HD 5770--HD: Western Digital Caviar Black 500 gb--ALI:: Corsair 650w--MONITOR: SyncMaster P2270--ROUTER: Netgear DG834G--SO: Win 7 Professional 64 bit |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 01:24.




















