Bonjour à tous,

J'ai eu le grand plaisir récemment de passer du cobol et de db2 à .NET avec du SQLServer. Appréciez le grand écart générationnel.

Voici mon problème :
Dans mon projet C#, j'ai une classe plaquette qui doit se connecter à la base de données sqlServer.

Pour ce faire, j'ai :
- paramétré des liens odbc vers les tables itou itou (suite à la lecture de certains topics sur ce meme forum)
- codé ça :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 
string Scnx = "Driver=SQL Server;Server=DNS_SERVER\\INSTANCE3;uid=monUIDspecialBDD;Trusted_connection=yes; pwd=monMegaPWD;dbq=CNC1_TARIF_NI;";
 
try
{
 // OdbcCommand CNC1_Cmd = new OdbcCommand(sSQL, CNC1_PLAQUETTE_Connexion);
Console.WriteLine("[existePlaquetteInDB] Avant using()");
 
using ( OdbcConnection cnx = new OdbcConnection (Scnx ) )
{
    Console.WriteLine("[existePlaquetteInDB] Avant new OdbcCommand()");
    OdbcCommand cmd = new OdbcCommand(sSQL, cnx);
    Console.WriteLine("[existePlaquetteInDB] Avant open()");
    cnx.Open();
 
    Console.WriteLine("[existePlaquetteInDB] Avant déclaration reader()");
    OdbcDataReader read = cmd.ExecuteReader();
 
      while (read.Read())
      {
       Console.WriteLine("[existePlaquetteInDB] read : " + read[0]);
      }
    Console.WriteLine("[existePlaquetteInDB] Avant fermeture reader()");
    read.Close();
 
} // fin using
 
}
catch (Exception ex)
{
Console.WriteLine("[existePlaquetteInDB] Un truc vient de casser. \n " + ex.ToString()); 
}

Prenons le coté positif des choses, ça compile.
Point négatif, j'ai une mignonne exception :

[existePlaquetteInDB] Avant using()
[existePlaquetteInDB] Avant new OdbcCommand()
[existePlaquetteInDB] Avant open()
[existePlaquetteInDB] Avant déclaration reader()
[existePlaquetteInDB] Un truc vient de casser.
System.Data.Odbc.OdbcException: ERROR [08004] [Microsoft][ODBC SQL Server Drive
r][SQL Server]The server principal "CDM\BONNARJU" is not able to access the data
base "CNC1_TARIF_NI" under the current security context.
à System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode re
tcode)
à System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior,
String method, Boolean needReader, Object[] methodArguments, SQL_API odbcApiMeth
od)
à System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior,
String method, Boolean needReader)
à System.Data.Odbc.OdbcCommand.ExecuteReader(CommandBehavior behavior)
à System.Data.Odbc.OdbcCommand.ExecuteReader()
à CNC1.Plaquette.existePlaquetteInDB() dans C:\Users\BONNARJU\Documents\Visua
l Studio 2005\Projects\CNC1\PlaquetteTarifaire\Plaquette.cs:ligne 112

Mon souci fondamental et joyeusement casse bonbon, réside dans le fait que si j'ouvre la connexion avec la chaine Scnx, j'ai la joie de ne pas avoir de problème de login, car monUIDspecialBDD est accepté par la bdd.
Alors que dans le using (ou sans parce que j'ai testé les 2), il veut me logguer avec mon identifiant windows (pas glop).


Des idées, des conseils ?



Par avance, merci.


Bisalité