Mike Eghtebas
asked on
Connection String... vb.net
The following code gives me an error: 40- could not open a connection to SQL Server.
Question: How can I handle this?
Question: How can I handle this?
Imports System.Data.SqlClient
Imports System.Data.SqlClient.SqlCommand
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim cnn As SqlConnection = New SqlConnection
Try
Dim strCnn As String = "Server='Mike-Vaio';Database='NORTHWND.MDF';Trusted_Connection=True;"
Dim cmd As SqlCommand = New SqlCommand("Select * From tblProduct", cnn)
cnn.ConnectionString = strCnn
cnn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader
If dr.HasRows Then
MessageBox.Show("Has Records")
Else
MessageBox.Show("Has no Records")
End If
' DataTable dt = new DataTable();
'dt.Load(dr);
'dataGridView1.DataSource = dt;
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
cnn.Close()
End Try
End Sub
End Class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
re:> and take a look at the online databases.
How do I do this?
How do I do this?
ASKER
Oh, under task 'Take Offline" shows enabled. This indicates it is already online.
BTW, I am using SQL Express 12 and vs2012
Also, I checked and found out the following:
SQL Server (SQLEXPRESS12) is running
SQL Server Agent (SQLEXPRESS12) is stopped
BTW, I am using SQL Express 12 and vs2012
Also, I checked and found out the following:
SQL Server (SQLEXPRESS12) is running
SQL Server Agent (SQLEXPRESS12) is stopped
ASKER
I was missinf SQLEXPRESS12 in:
Server='Mike-Vaio\SQLEXPRE SS12';Data base
Dim strCnn As String = "Server='Mike-Vaio';Databa se='NORTHW ND.MDF';Tr usted_Conn ection=Tru e;"
Server='Mike-Vaio\SQLEXPRE
Dim strCnn As String = "Server='Mike-Vaio';Databa
ASKER
I've requested that this question be closed as follows:
Accepted answer: 0 points for eghtebas's comment #a40362406
Assisted answer: 500 points for ste5an's comment #a40362293
for the following reason:
I was missinf SQLEXPRESS12 in:
Server='Mike-Vaio\SQLEXPRE SS12';Data base
Dim strCnn As String = "Server='Mike-Vaio';Databa se='NORTHW ND.MDF';Tr usted_Conn ection=Tru e;"
Accepted answer: 0 points for eghtebas's comment #a40362406
Assisted answer: 500 points for ste5an's comment #a40362293
for the following reason:
I was missinf SQLEXPRESS12 in:
Server='Mike-Vaio\SQLEXPRE
Dim strCnn As String = "Server='Mike-Vaio';Databa
So my answer was correct. You should give the points.
ASKER
I thought I gave the points, apparently there was a mistake.
Sorry,
Mike
Sorry,
Mike
ASKER
FYI, I have revised (changed and improved) my original question several times. My apology for this. I want just make sure you have read my latest version.
Mike