错误连接 [英] error connection

查看:86
本文介绍了错误连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好
我正在使用SQL Server作为donnée.losque的基础在vb.net中创建一个应用程序.我已建立与数据库的连接,并显示错误消息:无法登录用户".我会做任何事情来确保连接.
谢谢

Hello
I am creating an application in vb.net using SQL Server as the basis of donnée.losque I made the connection to the database, an error massage is displayed: "Failed to login user" I''d do anything to ensure the connection.
thank you

推荐答案

正在运行应用程序的上下文在SQL Server中应具有登录权限,以便它可以访问服务器.创建登录后,以适当的角色添加用户以进行数据库操作.

要创建登录帐户,您可以检查此

http://msdn.microsoft.com/en-us/library/ms189751.aspx [ ^ ]
Context on which the application is running should have a logon permission in the SQL server, so that it can access the server. Once the logon is created add the user in appropriate role for database operations.

To create login account you can check this

http://msdn.microsoft.com/en-us/library/ms189751.aspx[^]


导入System.ComponentModel
导入System.Text
导入System.Data.SqlClient
命名空间WindowsApplication1
部分公共类表格1
继承表格
Public Sub New()
InitializeComponent()
结束子

Private Sub button1_Click(按对象发送ByByVal发送者,按EventArgs接收ByVal e)处理button1.Click
试试
昏暗的连接作为新的SqlConnection(数据源= .;初始目录=主目录;集成安全性= true")
connection.Open()
如果connection.State = ConnectionState.Open然后
MessageBox.Show(已成功与SQL Server建立连接")
其他
MessageBox.Show("SQL Server连接失败")
如果结束
''INSTANT VB注意:变量E被重命名,因为Visual Basic不允许名称与参数或其他局部变量同名的局部变量:
捕获E_重命名为异常
MessageBox.Show(E_Renamed.Message.ToString())
结束尝试
结束子
结束类
结束命名空间
Imports System.ComponentModel
Imports System.Text
Imports System.Data.SqlClient
Namespace WindowsApplication1
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub

Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click
Try
Dim connection As New SqlConnection("Data Source=.;Initial Catalog=Master;Integrated Security=true")
connection.Open()
If connection.State = ConnectionState.Open Then
MessageBox.Show("Connection has been Successfully Established with SQL Server")
Else
MessageBox.Show("Connection Failed with SQL Server")
End If
''INSTANT VB NOTE: The variable E was renamed since Visual Basic will not allow local variables with the same name as parameters or other local variables:
Catch E_Renamed As Exception
MessageBox.Show(E_Renamed.Message.ToString())
End Try
End Sub
End Class
End Namespace


这篇关于错误连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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