Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Visual Basic .NET (http://www.programmingforums.org/forum19.html)
-   -   Connecting to SQL Server 2005 (http://www.programmingforums.org/showthread.php?t=14408)

Robocop Nov 10th, 2007 2:55 PM

Connecting to SQL Server 2005
 
What is the connection string I need to connect to a SQL Server 2005 Express Edition DB? (the mdf file)

I looked on ConnectionStrings.com , but wasn't able to find any.

Some help would be great! I'm using VB 2005

Thanks

Grich Nov 10th, 2007 6:49 PM

Re: Connecting to SQL Server 2005
 
developer fusion
carlprothman
Your connection string has to have this layout:
:

"Data Source=<host>; Initial Catalog=<Name of Database>; Integrated Security=True"
That is the minimum of what you need.
Some extra properties are as follows (these are optional):
Packet Size: Number of bytes in packet use to talk to SQL server.
User ID: User Name to log in.
Password: Password to login.
Workstation ID: Name of workstation to connect to SQL server.

(Hope this helps)

Robocop Nov 11th, 2007 11:37 AM

Re: Connecting to SQL Server 2005
 
I tried the connection string you provided, and it seems like it worked, but now I get an error on the DBConnection.Open() code line, after about 15 seconds of starting the debug process.

"Sql Exception was Unhandled"
"An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"

I'm running both the Sql Server(SQLEXPRESS) and Sql Server Browser services, and enabled TCP/IP.

This is the code:
:

Imports System.Data
Imports System.Data.Sql
Imports System.Data.SqlClient

Public Class frmMain
    Dim DBConnection As New SqlConnection
    Dim DBAdapter As SqlDataAdapter
    Dim intCurrentPosition As Integer
    Dim DBCommandBuilder As New SqlCommandBuilder

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        DBConnection.ConnectionString = "Data Source=c:\Inventory.mdf; Initial Catalog=Inventory; Integrated Security=True"
        DBConnection.Open()
        Dim DBAdapter As New SqlDataAdapter("Select * From tblItem", DBConnection)
        Dim DBCommandBuilder As New SqlCommandBuilder(DBAdapter)
    End Sub

    Private Sub frmMain_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        DBConnection.Close()
        DBConnection.Dispose()
    End Sub
End Class



Thanks for the help


All times are GMT -5. The time now is 8:21 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC