VB 2008 Express and SQL Server 2008

Connecting from VB 2008 to a database in SQL Server 2008

Page 1 of 1

2 Replies - 10298 Views - Last Post: 06 September 2009 - 02:58 PM Rate Topic: -----

#1 tpriede  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 05-September 09

VB 2008 Express and SQL Server 2008

Posted 05 September 2009 - 12:35 PM

Hi,
I'm trying to connect from VB 2008 Express Edition to a database in an instance of SQL Server 2008. Both, VB and SQL Server are running on the same machine.
From a VB project, when I try to define a new Data Connection I find just three Data sources available :

Microsoft Access Database File
Microsoft SQL Server Compact 3.5
Microsoft SQL Server Database File

Nothing to connect to the SQL Server Instance.

I selected the last one but when I browse for the mdf file I cannot select it because it tells me that the file is in USE. I have stopped all the services but still I'm not able to link the database file.

Two questions:
1.- Is there a way to connect to the SQL Server Instance and from there to select the desired database?
2.- How to connect using the Database file

Is This A Good Question/Topic? 0
  • +

Replies To: VB 2008 Express and SQL Server 2008

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4318
  • View blog
  • Posts: 12,100
  • Joined: 18-April 07

Re: VB 2008 Express and SQL Server 2008

Posted 05 September 2009 - 01:02 PM

SQL server runs multiple databases. The options you are presented there in the wizard is asking you which database you want to connect to. I suggest selecting the Microsoft SQL Server Database File option and then find the appropriate MDF for the database you want to attach to. You connect to the database through its file, not through the SQL server instance itself.

So once you select the Database File option, in the second box you browse to the MDF file (in the sql server DATA folder). Hit the test connection button to verify that you are successfully connected. The next step in the wizard will then ask you about building queries for your data adapter.

You should be all set. :)
Was This Post Helpful? 0
  • +
  • -

#3 tpriede  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 05-September 09

Re: VB 2008 Express and SQL Server 2008

Posted 06 September 2009 - 02:58 PM

Thank you for your answer. I had tried that approach before submitting the post but an error message prevented me to select the MDF database file. Once in the location where the MDF resides, when I try to open it I get the message "This file is in use. Enter a new name or close the file that's open in another program."
Any idea on why I get this message?
Thanks in advance.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1