2016-10-20 11 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サーバーが存在しないか、アクセスが拒否されているというエラーが常に表示されます。どのようにこの問題を解決するための任意のヘルプ?ポケットPC対

+0

質問を投稿する際に**実際の**ユーザー名とパスワードを含めないでください。それはあなたのためのものです。 –

+0

は既に編集されました。 – MDP

+0

データソース= STEPH-PC \ SQL2008;初期カタログ= MyDBに変更します。ユーザーID = myusername;パスワード= mypassword。 <インスタンス名の前にスペースを追加します。私はまた、ポートを提供する必要があるかもしれないことをお読みください。おそらく "統合セキュリティ= SSPI"を追加してください – josef

答えて

0

の1-テスト接続サーバー:

あなたのSQL Server CEモバイルエージェントは、SQL Server 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は仮想ディレクトリ名)。私はいつもあなたがインターネットに接続している必要があることを言及する必要があり、この時点で のMicrosoft SQL Server Compactの サーバーエージェント

:これを行うと、あなたのPocket 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 - お使いのPocket 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 

一般論:私がここに置くコードはデバッグする必要があります...私は私のプロジェクトからいくつかの部分を抽出してここに入れました。これがあなたを助けることを願っています!

関連する問題