Salut
Je voudrais demander votre aide, pour pouvoir executer mon programme. Je travail dans Visual Basic 2008 expression. Chaque fois que j'essaiye le debogage, je recois un message d'erreur au niveau de : Connect.Open(), lorsque j'ajoute createdatabase(). Je compte sur votre bonne volonte.
VOICI LE PROGRAMME EN QUESTION:
Imports System.Data.SqlClient
Public Class Central
Friend Sub CreateDatabase()
Dim strAction As String
Dim Command As SqlCommand = Nothing
Using Connect As SqlConnection = _
New SqlConnection("Data Source=(local); " & _
"Integrated Security='SSPI';")
strAction = "IF EXISTS ( " & _
"SELECT name " & _
"FROM sys.databases " & _
"WHERE name = N'GuineaBank1') " & _
"DROP DATABASE GuineaBank1; " & _
"CREATE DATABASE GuineaBank1"
Command = New SqlCommand(strAction, Connect)
Connect.Open()
Command.ExecuteNonQuery()
MsgBox("A database named GuineaBank1 " & _
"has been created.")
End Using
Using Connect As SqlConnection = _
New SqlConnection("Data Source=(local); " & _
"Database='GuineaBank1'; " & _
"Integrated Security='SSPI';")
strAction = "CREATE TABLE dbo.Account( " & _
"AccountID int Identity(1,1) NOT NULL, " & _
"BankAssets int Constraint FK_Bank " & _
" References Bank(BankAssets), " & _
"CustomerID int Constraint FK_Customer " & _
" References Customer(CustomerID), " & _
"AccountBalance nvarchar(50), " & _
"AccountType nvarchar(40) NOT NULL, " & _
"AccountCreateDate nvarchar(50), " & _
"AccountModifiedDate nvarchar(50), " & _
"AccountAgence nvarchar(30) NULL, " & _
"AccountPassword nvarchar(10) NULL, " & _
"AccountAwner nvarchar(50), " & _
"Notes ntext NULL, " & _
"CONSTRAINT PK_Account PRIMARY " & _
" KEY (AccountID));"
Command = New SqlCommand(strAction, Connect)
Connect.Open()
Command.ExecuteNonQuery()
MsgBox("A table named Account " & _
"has been added to the database.")
End Using
End Sub
Private Sub Central_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
CreateDatabase()
End Sub
End Class
VOICI LE MESSAGE D'ERREUR AU NIVEAU DE LA COMMANDE: Connect.Open()
error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)