2016-10-20 3 views
0

SQL Server 2008에서 vb.net을 사용하여 개발 한 Windows Mobile 응용 프로그램을 백엔드로 연결하는 데 문제가 있습니다. 다음은 연결 문자열입니다. 데이터 원본 = STEPH-PC \ SQL2008; 초기 카탈로그 = MyDB; 사용자 ID = myusername; 암호 = mypassword;Windows Mobile v 6.5 SQL Server 2008 R2에 연결

항상 SQL Server가 없거나 액세스가 거부되었다는 오류가 발생합니다. 이 문제를 해결하는 방법에 대한 도움이 필요하십니까? 포켓 PC 대

+0

질문을 게시 할 때 ** 실제 ** 사용자 이름과 비밀번호를 포함하지 마십시오. 그것은 당신 자신의 이익을위한 것입니다. –

+0

이미 감사드립니다. – MDP

+0

데이터 원본 = STEPH-PC \ SQL2008로 변경, 초기 카탈로그 = MyDB; 사용자 ID = myusername; 암호 = mypassword; <인스턴스 이름 앞에 공백을 추가하십시오. 또한 포트를 제공하는 것이 필요할 수도 있음을 읽었습니다. 아마도 "통합 보안 = SSPI"를 추가하십시오 – josef

답변

0

1 테스트 연결 서버 : SQL 서버 CE 모바일 에이전트는 SQL 서버 CE 서버 에이전트에 연결하는 경우 모든 테스트에서

첫째. 이렇게하려면 서버와 Pocket PC에 SQL Server CE 3.5를 설치해야합니다. Google에서 검색 SQL Server CE 3.5를 설치하는 방법. 이 과정에서 서버에 가상 디렉토리를 만들고 해당 디렉토리에 sqlcesa35.dll 파일이 있으므로 Pocket PC 브라우저에서 연결을 테스트하려면 다음을 작성하십시오. http://ipserver/virtual_directory/sqlcesa35.dll (물론 ipserver는 서버 IP 여야하고 virtual_directory는 가상이어야합니다 디렉토리 이름). 난 항상 당신이 인터넷에 연결되어 있어야합니다 언급해야 할이 시점에서 마이크로 소프트의 SQL Server Compact 서버 에이전트

: 당신이 이렇게하면 당신의 포켓 PC에서 메시지를 얻을 수 있습니다.

2 서버에서 파일 가져 오기 (이 코드는 디버깅되지 않은 샘플 코드이며 다른 프로젝트의 일부만 가져 와서 여기에 넣어 두었습니다).

Function get_companies(ByVal sSucursal As String, ByVal cn_Interface As System.Data.SqlServerCe.SqlCeConnection, _ 
    ByVal cmd_Interface As System.Data.SqlServerCe.SqlCeCommand, ByVal dr_Interface As System.Data.SqlServerCe.SqlCeDataReader) As Boolean 

    get_companies = False 

    Dim _strRemoteConnect As String 
    Dim _strLocalConnect As String 
    Dim _strInternetURL As String = sInternetURL 
    'The last variable sInternetURL is something like: http://ip_server/virtual_directory/sqlcesa35.dll 

    _strRemoteConnect = "Provider=SQLOLEDB;Data Source=" & sIPSQLServer & ";Initial Catalog=" & sBDSQLServer & ";User Id=" & sUserSQLServer & ";Password=" & sClaveSQLServer 
    'sIPSQLServer is the server ip where is running SQL Server 
    'sBDSQLServer is your DataBase server. 
    _strLocalConnect = "Data Source=" & sPath & "\" & sDataBase_Interface & "; Password=" & sPassword 
    'sPath is your directory in your Pocket PC, begings with \ 
    'sDataBase_Interface is the database in my Pocket PC, an .sdf file 

    Dim rda As System.Data.SqlServerCe.SqlCeRemoteDataAccess = New System.Data.SqlServerCe.SqlCeRemoteDataAccess 
    rda.InternetLogin = sUserInternet 'a valid user in your domain 
    rda.InternetPassword = sClaveInternet 
    rda.InternetUrl = _strInternetURL 
    rda.LocalConnectionString = _strLocalConnect 

    Do While True 
     Try 
      'In server database there is a table: Monedas 
      rda.Pull("_Monedas", "Select Moneda, Descripcion, Abreviada From Monedas Where Sucursal = '" & sSucursal & "'", _ 
             _strRemoteConnect, System.Data.SqlServerCe.RdaTrackOption.TrackingOff) 
      Exit Do 
     Catch exc As System.Data.SqlServerCe.SqlCeException 
      ShowErrorSqlServerCE(exc) 
     Catch ex As Exception 
      MessageBox.Show(ex.Message) 
     End Try 
    Loop  

    'read the data received, just testing, may be this code not to be here because you process the data outside the function. 
    Try 
     cmd_Interface.CommandText = "Select Moneda, Descripcion, Abreviada From _Monedas" 
     dr_Interface = cmd_Interface.ExecuteReader() 

     Do While dr_Interface.Read() 
      messagebox.show("Moneda = " & dr_interface("Moneda") & " - " & dr_interface("Descripcion") & " - " & dr_interface("Abreviada"), _ 
      "Currencies Received", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1) 
     Loop 
     get_companies = true 
    Catch exc As System.Data.SqlServerCe.SqlCeException 
     ShowErrorSqlServerCE(exc) 
    Catch ex As Exception 
     MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)  
    Finally 
     'If cn_Interface.State <> ConnectionState.Closed Then 
     ' cmd_Interface.Dispose() 
     ' cn_Interface.Close() 
     ' cn_Interface.Dispose() 
     'End If 
    End Try 
End Function 

3 포켓 PC에서 데이터베이스 서버의 문장을 Excecuting 및 서버에 포켓에서 데이터를 전송 : 내가 위에서 말했듯이

Function DropTableP(ByVal sTabla As String) As Boolean 
    'Dim cn_Interface As System.Data.SqlServerCe.SqlCeConnection 
    'Dim cmd_Interface As System.Data.SqlServerCe.SqlCeCommand 
    'Dim dr_Interface As System.Data.SqlServerCe.SqlCeDataReader 
    Dim nRegs As Integer 

    Try 
     'cn_Interface = New System.Data.SqlServerCe.SqlCeConnection("Data Source=" & sPath & "\" & sDataBase_Ppal & "; Password=" & sPassword) 
     'cn_Interface.Open() 

     'cmd_Interface = cn_Interface.CreateCommand() 
     'cmd_Interface.CommandType = CommandType.Text 
     cmd.CommandText = "Select TABLE_NAME From INFORMATION_SCHEMA.TABLES Where TABLE_NAME = '" & sTabla & "'" 
     dr = cmd.ExecuteReader() 
     If dr.Read() Then 
      dr.Close() 
      dr.Dispose() 

      cmd.CommandText = "DROP TABLE " & sTabla 
      nRegs = cmd.ExecuteNonQuery() 
      DropTableP = True 
     Else 
      dr.Close() 
      dr.Dispose() 
      DropTableP = True 
     End If 
    Catch exc As System.Data.SqlServerCe.SqlCeException 
     ShowErrorSqlServerCE(exc) 
    Catch ex As Exception 
     MessageBox.Show(ex.Message) 
    Finally 
     'If cn_Interface.State <> ConnectionState.Closed Then 
     ' cn_Interface.Close() 
     ' cn_Interface.Dispose() 
     'End If 
    End Try 
End Function 

Sub ShowErrorSqlServerCE(ByVal exc As System.Data.SqlServerCe.SqlCeException) 
    Dim bld As New System.Text.StringBuilder 
    Dim err As System.Data.SqlServerCe.SqlCeError 
    Dim errorCollection As System.Data.SqlServerCe.SqlCeErrorCollection = exc.Errors 
    Dim errPar As String 
    Dim numPar As Integer 

    ' Loop through all of the errors. 
    For Each err In errorCollection 
     bld.Append(ControlChars.Cr & " Error Code: " & err.HResult.ToString("X")) 
     bld.Append(ControlChars.Cr & " Message : " & err.Message) 
     bld.Append(ControlChars.Cr & " Minor Err.: " & err.NativeError) 
     bld.Append(ControlChars.Cr & " Source : " & err.Source) 

     ' Loop through all of the numeric parameters for this specific error. 
     For Each numPar In err.NumericErrorParameters 
      If numPar <> 0 Then 
       bld.Append(ControlChars.Cr & " Num. Par. : " & numPar.ToString()) 
      End If 
     Next numPar 

     ' Loop through all of the error parameters for this specific error. 
     For Each errPar In err.ErrorParameters 
      If errPar <> [String].Empty Then 
       bld.Append(ControlChars.Cr & " Err. Par. : " & errPar) 
      End If 
     Next errPar 

     ' Finally, display this error. 
     MessageBox.Show(bld.ToString(), "SQL Server CE") 

     ' Empty the string so that it can be used again. 
     bld.Remove(0, bld.Length) 
    Next err 
End Sub 

:

Function EnviarClientesNuevos(ByVal sSucursal As String, ByVal sZona As String, ByVal sRuta As String) As Boolean 
    Dim sLineas As String 
    Dim nRegs As Integer 

    Dim cn_Interface As System.Data.SqlServerCe.SqlCeConnection 
    Dim cmd_Interface As System.Data.SqlServerCe.SqlCeCommand 

    EnviarClientesNuevos = False 

    Dim _strRemoteConnect As String 
    Dim _strLocalConnect As String 
    Dim _strInternetURL As String = sInternetURL 

    _strRemoteConnect = "Provider=SQLOLEDB;Data Source=" & sIPSQLServer & ";Initial Catalog=" & sBDSQLServer & ";User Id=" & sUserSQLServer & ";Password=" & sClaveSQLServer 
    _strLocalConnect = "Data Source=" & sPath & "\" & sDataBase_Interface & "; Password=" & sPassword 

    Dim rda As System.Data.SqlServerCe.SqlCeRemoteDataAccess = New System.Data.SqlServerCe.SqlCeRemoteDataAccess 
    rda.InternetLogin = sUserInternet 
    rda.InternetPassword = sClaveInternet 
    rda.InternetUrl = _strInternetURL 
    rda.LocalConnectionString = _strLocalConnect 

    Do While True 
     If DropTableE("_NEW_CLIENTES_XX") Then 
      Try 
       '_NEW_CLIENTES_XX is a table in your SQL Server (The server, not the Pocket) 
       rda.Pull("_NEW_CLIENTES_XX", "Select Id, Sucursal, Zona, CodCli, Nombre, Direccion, Ruc, Clase, Ruta " & _ 
       "FROM _NEW_CLIENTES_XX WHERE Sucursal = ''", _strRemoteConnect, SqlServerCe.RdaTrackOption.TrackingOn) 
       'In where clause I compare to '' because I only need the structure 
       Exit Do 
      Catch exc As System.Data.SqlServerCe.SqlCeException 
       ShowErrorSqlServerCE(exc) 
       Exit Function 
      Catch ex As Exception 
       MessageBox.Show(ex.Message) 
       Exit Function 
      End Try 
     End If 
    Loop 

    Try 
     '-- 
     cn_Interface = New System.Data.SqlServerCe.SqlCeConnection 
     cn_Interface.ConnectionString = "Data Source=" & sPath & "\" & sDataBase_Interface & ";Password=" & sPassword 
     cn_Interface.Open() 

     cmd_Interface = cn_Interface.CreateCommand() 
     cmd_Interface.CommandType = CommandType.Text 
     '-- 

     'here I have an open connection to another database in my Mobile Device. Here I have to mention that I work with 2 databases in my mobile device: 
     'One database for getting the data from server, I only use it when I get data from server and when I send data to server 
     'and other database which is my main database, the database that is used all the day storing customers transactions. 
     'here I already have open (outside this function) the connection to this second database, but the sentence are the same above, 
     'something like this: 
     'Try 
     ' cn = New System.Data.SqlServerCe.SqlCeConnection 
     ' cn.ConnectionString = "Data Source=" & sPath & "\" & sDataBase_Ppal & ";Password=" & sPassword 
     ' cn.Open() 

     ' cmd = cn.CreateCommand() 
     ' cmd.CommandType = CommandType.Text 

     'Read the data from my main Pocket PC database   
     cmd.CommandText = "SELECT CodCli, Nombre, Direccion, Ruc, Clase From CLIENTES WHERE CLASE IN ('N', 'M')" 
     dr = cmd.ExecuteReader() 
     Do While dr.Read() 
      'Insert the data in the table structure that I get above. 
      'remember that this table is in the database that only is used when transferring data, its a temporal database. 
      cmd_Interface.CommandText = "INSERT INTO _NEW_CLIENTES_XX (Sucursal, Zona, CodCli, Nombre, Direccion, Ruc, Clase, Ruta) " & _ 
           "VALUES('" & sSucursal & "', '" & sZona & "', " & dr("CodCli") & ", '" & _ 
           dr("Nombre") & "', '" & dr("Direccion") & "', '" & dr("Ruc") & "', '" & _ 
           dr("Clase") & "', '" & sRuta & "')" 

      nRegs = cmd_Interface.ExecuteNonQuery() 
     Loop 
     dr.Close() : dr.Dispose()   
    Catch exc As System.Data.SqlServerCe.SqlCeException 
     ShowErrorSqlServerCE(exc) 
     Exit Function 
    Catch ex As Exception 
     MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1) 
     Exit Function 
    Finally 
     Try 
      dr.Close() 
      dr.Dispose() 
     Catch ex As Exception 
     End Try 

     'If cn.State <> ConnectionState.Closed Then 
     ' cmd.Dispose() 
     ' cn.Close() 
     ' cn.Dispose() 
     'End If 

     If cn_Interface.State <> ConnectionState.Closed Then 
      cmd_Interface.Dispose() 
      cn_Interface.Close() 
      cn_Interface.Dispose() 
     End If 
    End Try 

    Do While True 
     Try 
      'I excecute a sentence in the Server. I delete the data in _NEW_CLIENTES_XX which is a work table in SQL server. 
      rda.SubmitSql("Delete From _NEW_CLIENTES_XX Where Sucursal = '" & sSucursal & "' AND Zona = '" & sZona & "' And Ruta = '" & sRuta & "'", _strRemoteConnect) 

      'I send the data to server 
      rda.Push("_NEW_CLIENTES_XX", _strRemoteConnect, System.Data.SqlServerCe.RdaBatchOption.BatchingOn) 

      EnviarClientesNuevos = True 

      Exit Do 
     Catch exc As System.Data.SqlServerCe.SqlCeException 
      ShowErrorSqlServerCE(exc) 
      Exit Function 
     Catch ex As Exception 
      MessageBox.Show(ex.Message) 
      Exit Function 
     End Try 
    Loop   
End Function 

일반적 : 여기에 넣은 코드는 디버깅해야합니다 ... 저는 프로젝트에서 일부만 추출하여 여기에 넣었습니다. 희망이 당신을 도울 것입니다!

관련 문제