Dear all,

I have created an SQL Server 2005 Express database using the database explorer of VB.Net 2005, and selected to copy the database to the application folder.

I can successfully connect and update the tables using Visual Basic ready tools (such as datagrid). But when I try to connect to the same database by code I fail. The debugger always stops at the connection line which I apparently write it incorrectly.

What would this connection command be if the database is called 'Inventory.mdf' and located at 'C:\Inventory\Inventory.mdf'?

Thanks for help in advance

Recommended Answers

All 2 Replies

First, you never ever connect to a database file (*.mdf) directly. You connect to the database, which knows where it's files are and handles them.

I didn't have a good (simple) example how to connect to the SQL Server. So I'll give you few links to get started. First you'll need to get familiar with System.Data.SqlClient namespace. Second thing to learn are connection strings.

Objects that you need to make a basic SQL Server connection and get the basic "functionality" are Connection and Command from the System.Data.SqlClient namespace. I also assume you're familiar with SQL. If you're not, try to google some SQL tutorial.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.