我制作了一个简单的.net wpf应用程序,用于在两个不同的sql数据库之间进行数据同步,并且它可以正常工作。但是现在我想构建另一个将在两个不同服务器之间同步数据的服务器,一个是本地的,另一个是使用sqldatareader的远程(基于IP)的服务器。全部设置但在运行时得到错误“从字符串“ Data Source = MOONLOADER \ MSSQLSERV转换为类型'integer”无效” 我已经习惯了像conl这样的sql连接,像local一样,conr作为remote。来自app.config的conl和主窗口连接字符串中的conr。 我的代码在下面
主窗口:
Imports System.Data
Imports System.Data.Sql
Imports System.Data.SqlClient
Imports System.Configuration
Class MainWindow
Dim sqlcon As New SqlConnection
Dim cmd As New SqlCommand
Dim conl As String = ConfigurationManager.ConnectionStrings("conl").ConnectionString
Dim conr As String = "Data Source=MOONLOADER\MSSQLSERVER2005;Initial Catalog=SSBYM;User ID=sa;Password=sasa;"
Dim da As New SqlDataAdapter()
Private Function GetConnectionString() As String
Return System.Configuration.ConfigurationManager.ConnectionStrings("conr").ConnectionString
End Function
Private Sub btnupload_Click(sender As Object, e As RoutedEventArgs) Handles btnupload.Click
Try
Dim dr = cmd.ExecuteReader(conl)
sqlcon = New SqlConnection(conl)
sqlcon = New SqlConnection(conr)
cmd.Connection = New SqlConnection(conl)
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "select1"
sqlcon.Open()
cmd.ExecuteReader()
dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
dr.Read()
dr.Close()
cmd.Connection = New SqlConnection(conr)
cmd.CommandType = CommandType.Text
cmd.CommandText = ("insert into dbo.TxnEnrollment")
sqlcon.Open()
da = New SqlDataAdapter
sqlcon.Close()
MessageBox.Show("Uploaded Successfully")
Catch ex As Exception
MessageBox.Show(ex.Message.ToString())
End Try
End Sub
End Class
app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<connectionStrings>
<add name ="conl" connectionString="Data Sorce=MOONLOADER\MSSQLSERVER2005;Initial Catalog=SSBY;User ID=sa;Password=sasa"/>
</connectionStrings>
</configuration>
运行后出现错误=“从字符串” Data Source = MOONLOADER \ MSSQLSERV“转换为'integer'类型无效”
我该如何解决?