Bonjour,

Voici mon problème:

J'ai un WebService qui doit insérer une ligne dans une base de donnée

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
33
34
35
36
37
<WebMethod()> _
    Public Function OuvertureConnection(ByVal id_bdd As String) As Integer
        'On Error GoTo Fin
        Dim id_connection As New Integer
        Dim myconnection As New SqlConnection()
        Dim mycommand As SqlCommand
        Dim mycommand2 As SqlCommand
        Dim mycommand3 As SqlCommand
        Dim rs As DateTime
        Dim IP As String
        Dim DateDuJour As DateTime
        IP = HttpContext.Current.Request.UserHostAddress
 
 
        myconnection = New SqlConnection("Data Source=66.199.222.999,1433;Network Library=DBMSSOCN;Initial Catalog=" & id_bdd & ";User ID=toto;Password=azerty;")
        myconnection.Open()
 
        mycommand3 = New SqlCommand("select convert(datetime,convert(char(10),getdate(),103),103)")
        mycommand3.Connection = myconnection
        mycommand3.ExecuteNonQuery()
        rs = mycommand3.ExecuteScalar
        DateDuJour = rs
        mycommand = New SqlCommand("insert into Connexion (IP,Date) values( '" & IP & "' ,convert(datetime,'" & DateDuJour & "'))")
        mycommand.Connection = myconnection
        mycommand2 = New SqlCommand("select max(IdConnexion) from Connexion Where IP='" & IP & "'")
        mycommand2.Connection = myconnection
 
        mycommand.ExecuteNonQuery()
        rs = mycommand2.ExecuteScalar
        id_connection = Int(rs.ToString)
 
        'Fin:
        'mycommand.Cancel()
        'mycommand2.Cancel()
        myconnection.Close()
        Return id_connection
    End Function
La conexion à la base de données fonctionne, mais lorsque je souhaite éxecuter la requete INSERT j'ai l'erreur:

La conversion d'un type de données varchar en type de données datetime a créé une valeur hors limites.
L'instruction a été arrêtée.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: La conversion d'un type de données varchar en type de données datetime a créé une valeur hors limites.
L'instruction a été arrêtée.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Pourtant DateDuJour est bien de type DateTime, je le convertit même à nouveau en datetime dans la requete pour en être sur!

Ou est le problème?