Connection Problems

  • Thread starter Thread starter gwboolean
  • Start date Start date
G

gwboolean

Guest
I am having trouble with my connection setup.

I have database that I created using SQL Express 2017

I am currently using the following connection string for an application I use to test query methods. The connection string can be defined for any database.

So, when I execute this I get the message noted below, and of course I cannot connect to the database. However, If I use a database not created by me (vis-à-vis not using my SQL Express) I have no problem connecting with the database.

So can anyone help me figure out what I have done that is causing this?

'Connection Variables
Dim MyConnection As SqlConnection
'Define connection
Dim strConnection As String = "Data Source=.\SQLEXPRESS; AttachDbFilename=F:\SiTechMasterBase1.2\DataBase\MasterBase2.0.mdf; Integrated Security=True; Connect Timeout=30; User Instance=True"

Private Sub frmSQLTester_Load(sender As Object, e As EventArgs) Handles MyBase.Load
MyConnection = New SqlConnection(strConnection)
MyConnection.Open()
End Sub

Private Sub btnTest_Click(sender As Object, e As EventArgs) Handles btnTest.Click
Dim MyCommand As SqlCommand = Nothing
Dim MyAdapter As New SqlDataAdapter
Dim MyTable As New DataTable

Try
'establish command object and data adapter
MyCommand = New SqlCommand(txtSQLTester.Text, MyConnection) 'Input SQL Query parameters into textbox.
MyAdapter.SelectCommand = MyCommand
MyAdapter.Fill(MyTable)
'bind grid view to data table
grdSQLTester.DataSource = MyTable
lblRecords.Text = MyTable.Rows.Count.ToString
Catch SQLExceptionErr As SqlException
MessageBox.Show(SQLExceptionErr.Message, "Access Error. General exception.")
Catch InvalidOperationExceptionErr As InvalidOperationException
MessageBox.Show(InvalidOperationExceptionErr.Message, "Access Error. Invalid Operaion.")
Catch ex As Exception
MessageBox.Show(ex.Message, "Error in Processing SQL", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

MyCommand.Dispose()
MyAdapter.Dispose()
MyTable.Dispose()
End Sub
1309044.jpg




gwboolean

Continue reading...
 
Back
Top