|
The ProgrammingMSAccess.COM Site This procedure demonstrates how to load a database on a Server from an .mDF FILE WITH a sqlcOMMAND OBJECT. Private Sub AttachHCVBMDF(ByVal sender As System.Object, _ByVal e As System.EventArgs) Handles Button5.Click
'Declare, instantiate, and open a connection Dim cnn1 As SqlClient.SqlConnection = _New SqlClient.SqlConnection( _ "Data Source=CABLAT\CABLATDEVELOPER;" & _ "Integrated Security=SSPI") cnn1.Open()
'Invoke the sp_attach_single_file_db system 'stored procedure with a SQLCommand object to 'create a SQL Server database from an .mdf file Dim strSQL1 As String = _"EXEC sp_attach_single_file_db " & _ "@dbname = 'HCVB', " & _ "@physname = " & _ "C:\Documents and Settings\Administrator" & _ "\My Documents\HCVB_Data.MDF'" Dim cmd1 As SqlClient.SqlCommand = _ New SqlClient.SqlCommand(strSQL1, cnn1) Try cmd1.ExecuteNonQuery() Catch ex1 As SqlClient.SqlException MsgBox(ex1.Message) End Try
cnn1.Close()
End Sub
Learn more about VB.NET programming from either Programming Microsoft SQL Server 2000 with Microsoft Visual Basic .NET or Programming Microsoft Visual Basic .NET for Microsoft Access Databases. Copyright 2003 CAB, Inc. All rights reserved. Republication or redistribution
of CAB, Inc. content, including by framing or similar means, is expressly
prohibited without the prior written consent of CAB, Inc. CAB, Inc. shall not be
liable for any errors in the content, or for any actions taken in reliance
thereon.
|