|
-
Dec 9th, 2004, 08:47 AM
#1
Thread Starter
Member
Error in Connecting to SQl server2000 Sample Northwind database
I'm just started out learning programming SQL server 2002 with visual basic.net or visa versa. I have a book entitled "Programming Microsoft SQL Server 2000 with Microsoft Visual Basic.net". There is a CD containing sample vb.net application codes to facilitate the learning of programming...
Now when i run and compiled the sample source code, there is this error:
Unhandled Exception: System.Data.SqlClient.SqlException: SQL Server does not exist or access denied.
at System.Data.SqlClient.SqlConnection.Open()
at MyADODOTNETSamples.Module1.IntegratedCnnToNorthwind() in D:\SQLVBNET\Chapter_10\MyADODOTNETSamples\Module1.vb:line 29
at MyADODOTNETSamples.Module1.main() in D:\SQLVBNET\Chapter_10\MyADODOTNETSamples\Module1.vb:line 6The program '[2788] MyADODOTNETSamples.exe' has exited with code 0 (0x0).
I have sqlserver 2000 installed. And i have run sqlserver 2000 enterprise manager. I can see that Northwind database is in my system.
The vb.net codes are as follows:
Imports System.Data.SqlClient
Module Module1
Sub main()
IntegratedCnnToNorthwind()
'SQLServerCnnToNorthwind()
'CatchSQLClientException()
'EnumerateCategories()
'EnumerateCustomerIDNames(25)
'RunCustOrderHistWithString("TORTU", 10)
'RunCustOrderHistWithParameter("TORTU", 10)
'CreateAndInvokeUDF(10249, 3)
'ShowForm2Bindings()
End Sub
Sub IntegratedCnnToNorthwind()
'Specify connection string for connection via user's
'Windows login; make sure user's Window login has access
'to the Northwind database or the Northwind database has
'its guest user account.
Dim cnn1 As SqlConnection = _
New SqlConnection("Data Source=(local);" & _
"Initial Catalog=northwind;Integrated Security=SSPI")
'Attempt to open Northwind database with user's Windows login.
cnn1.Open()
'Echo connection string to either Debug window
'or a message box.
Debug.WriteLine(cnn1.ConnectionString)
'MsgBox(cnn1.ConnectionString)
'Close connection object to dispose of it.
cnn1.Close()
End Sub
Sub SQLServerCnnToNorthwind()
'Specify connection string for connection via vbdotnet1
'SQL Server login; make sure vbdotnet1 login has access
'to the Northwind database via its own account or guest account.
Dim str1 As String = "Data Source=(local);" & _
"Initial Catalog=northwind;" & _
"user id = vbdotnet1; password=passvbdotnet1"
Dim cnn1 As SqlConnection = _
New SqlConnection(str1)
'Attempt to open Northwind database with vbdotnet1 login.
cnn1.Open()
'Echo connection string
Debug.WriteLine(cnn1.ConnectionString)
'Close connection object to dispose of it.
cnn1.Close()
End Sub
Anyone has any solutions or suggestions or teachings? Thanks alot.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|