使用VB.NET与SQL通信 [英] communicate with SQL using VB.NET

查看:73
本文介绍了使用VB.NET与SQL通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我使用VB.NET 2008 tring创建了一个非常简单的服务,可以使用以下代码与SQL Server交互(向表中添加一条记录):

Hello everyone,

I created a very smiple service using VB.NET 2008 tring to interact with SQL server (adding one record to table) using the following code:

Imports System.Data.SqlClient

Public Class Imsglobe_syncLocal

    Protected Overrides Sub OnStart(ByVal args() As String)
        ' Add code here to start your service. This method should set things
        ' in motion so your service can do its work.
      
        Dim sqlstr As String
        Dim ds As New Global.System.Data.DataSet

        Dim constr As String = "Data Source=(local);Initial Catalog=InfoBank;Integrated Security=True"
        Dim Cmd As Global.System.Data.SqlClient.SqlCommand

        sqlstr = "INSERT INTO [dbo].[Root_tbl]  ([RootName] ,[UsrLevel]) VALUES ('testing',5)"
        Dim Con As Global.System.Data.SqlClient.SqlConnection = New Global.System.Data.SqlClient.SqlConnection(constr)
        Con.Open()
        Cmd = New Global.System.Data.SqlClient.SqlCommand(sqlstr, Con)
        Cmd.ExecuteNonQuery()
        Cmd.Dispose()
        Con.Close()

    End Sub



看来此方法不适用于该服务.
任何提示将不胜感激.
在此先谢谢您.



It seems this method is not working with the service.
Any hint will be appreciated.
Thanks in advance.

推荐答案

尝试使用SQL帐户而不是集成的安全性.
这可能是权限问题.
还说出您在哪里得到错误以及它是什么.
以某种形式进行这项工作几乎可以证明我的观点是身份验证.如果您在服务中遇到错误,请写入错误日志,该错误是什么,我敢打赌这是权限.您可以通过仅更改用户的连接字符串来证明这一点,也许现在可以通过证明
Try using an sql account and not integrated security.
it may be a permissions issue.
also say where you are getting an error and what it is .
having this work in a forms almost proves my point it is the authentication. if you get an error while in the service write to the error log what the error is and I will bet it is permissions. you can prove it by just change the connection string to a user maybe sa to prove it for now


这篇关于使用VB.NET与SQL通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆