Read a SQL xXpress Created Database

Hi All,

I am a newbie. I am using SQL SERVER EXPRESS ( Free Version ) and the
Free version of VB.net 2005. I have created a Database inside the VB.net
IDE and can use it with the program fine. How do I view this same database
with another program ? I found the Database viewer and I can't seem to get this program to read the database. I am not sure what the connection
values should be using this program to read a mdf file created by SQL EXPRESS.

Fo Instance my when I login to SQLSERVER express management console the dialog box uses the following :

Server Type : Database Engine
Server Name : MATPM\SQLEXPRESS
Authentication : Windows Authentication
User Name : myname
Password :

This database view app I found shows a SQL dialog box like below

User Name : sa
Password:
Database :
SQL Server:

What do I do here ? I had put the path to the *.mdf file and all combinations
and I can't open the database. I can use database explorer in VB.net to create databases and alter them. What does it use as a connection string ?
How do I access databases created by visual studio. I want to write a Program that uses databases and I want a VB program to switch between them and create new ones. Is there a sample program here someplace?

Nick
[1380 byte] By [NV2002] at [2007-11-20 11:25:33]
# 1 Re: Read a SQL xXpress Created Database
Posting EXEs as attachments is not a good idea.
Post the connection string that causes the issue.
hspc at 2007-11-9 13:45:41 >
# 2 Re: Read a SQL xXpress Created Database
Thanks for the advice. I deleted the exe and re worded my question :

Hi All,

I am a newbie. I am using SQL SERVER EXPRESS ( Free Version ) and the
Free version of VB.net 2005. I have created a Database inside the VB.net
IDE and can use it with the program fine. How do I view this same database
with another program ? I found the Database viewer and I can't seem to get this program to read the database. I am not sure what the connection
values should be using this program to read a mdf file created by SQL EXPRESS.

Fo Instance my when I login to SQLSERVER express management console the dialog box uses the following :

Server Type : Database Engine
Server Name : MATPM\SQLEXPRESS
Authentication : Windows Authentication
User Name : myname
Password :

This database view app I found shows a SQL dialog box like below

User Name : sa
Password:
Database :
SQL Server:

What do I do here ? I had put the path to the *.mdf file and all combinations
and I can't open the database. I can use database explorer in VB.net to create databases and alter them. What does it use as a connection string ?
How do I access databases created by visual studio. I want to write a program that uses databases and I want a VB program to switch between them and create new ones. Is there a sample program here someplace.

Nick
NV2002 at 2007-11-9 13:46:42 >
# 3 Re: Read a SQL xXpress Created Database
I prefer that you create the database from SQL Server management studio not from VB.NET IDE.
VB.NET express IDE creates the database files and attaches them at runtime (in the connection string which you can find in the app.config file)

However in your case, You can use the already created DB by attaching it from SQL Management studio (Right click databases node -> attach).

you can connect to this DB using a connection string like:
Data Source=.\SQLEXPRESS;Integrated Security=True;Connect Timeout=30;Database=DATABASENAME;User Instance=False
hspc at 2007-11-9 13:47:41 >
# 4 Re: Read a SQL xXpress Created Database
Hi hspc,

Thanks for your response although I am still a bit confused as to the order of things. So what you are telling me is that a "Databse" must be attached to the Sql Server before it can be opened ? How does VB.net open it as it wasn't attached until I just did it as you instructed ?

Here is the code snippet that builds the Database connection string :

Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0" & _
"Data Source=" & Me.database & "" & _
"Jet OLEDB:System database=" & SQLServer & "User ID =" & userName & "Password =" & password & ""
m_sConnectString = connString
database.connectString = connString
connectedFlag = database.Connect()

It will look nothing like the string example you gave. I gues what I am asking is how can I open or change or create databases under VB.net control. Suppose I wanted to write a program that keeps track of DVD movies. I want to be able to create and load multiple databases and manipuate them via a VB.net program. Do you know of any sample apps that show how this is done? I thought it was like when you create a text file. Many apps open the text file.

Thanks in Advance,

Nick
NV2002 at 2007-11-9 13:48:36 >
# 5 Re: Read a SQL xXpress Created Database
Do you use MS SQL Server 2005 or MS Access?
the provider you use is "Microsoft.Jet.OLEDB.4.0" which is oledb provider for ms access !!
the connection string I sent is for SQL Server using native provider (SqlConnection , SqlCommand instead of OleDbConnection and OleDbCommand etc).
What I meant about attaching the DB:
It's Either attached permanently or per connection (as VB.NET IDE generated code does)

For your requirement, you may use multiple MS Access databases and change the path of *.mdb file in the connection string according to the database you want to connect to.
hspc at 2007-11-9 13:49:36 >
# 6 Re: Read a SQL xXpress Created Database
No SQL is correct. This sample program shows that it can connect to either and apparently the logic is incorrect and perhaps that is why the program will not connect to the SQL express database ? This sample I could not get to compile so I am stuck with the EXE in the zip I found it from.
I am going to try to write my own using the connection string method that you outlined. I will keep you posted. Maybe it is the program and not what
I was entering. Thanks...
NV2002 at 2007-11-9 13:50:47 >