Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 10th, 2007, 2:55 PM   #1
Robocop
Programmer
 
Join Date: Sep 2004
Posts: 47
Rep Power: 0 Robocop is on a distinguished road
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
Robocop is offline   Reply With Quote
Old Nov 10th, 2007, 6:49 PM   #2
Grich
Hobbyist Programmer
 
Grich's Avatar
 
Join Date: Sep 2007
Location: Sydney - Australia
Posts: 192
Rep Power: 2 Grich is on a distinguished road
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)
__________________
SYNTAX ERROR ...

Last edited by Grich; Nov 10th, 2007 at 6:50 PM. Reason: Add on
Grich is offline   Reply With Quote
Old Nov 11th, 2007, 11:37 AM   #3
Robocop
Programmer
 
Join Date: Sep 2004
Posts: 47
Rep Power: 0 Robocop is on a distinguished road
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
Robocop is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Detach an in-use database via code (SQL Server 2000) sma_soft C# 1 Aug 14th, 2007 2:22 PM
server - messenger chat... programmingnoob Coder's Corner Lounge 6 Jul 19th, 2007 6:36 AM
Help with C# TCP/IP Server csrocker101 C# 3 Mar 15th, 2007 12:32 AM
FTP Server in Python Sane Python 1 Mar 31st, 2006 10:25 PM
weird output in my server program nindoja C++ 21 Nov 24th, 2005 9:31 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:34 AM.

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