Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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
Posted

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[^]
 
Share this answer
 
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900