![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Programmer
Join Date: Sep 2004
Posts: 47
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Sep 2007
Location: Sydney - Australia
Posts: 192
Rep Power: 2
![]() |
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" 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 |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Sep 2004
Posts: 47
Rep Power: 0
![]() |
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 ClassThanks for the help |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |