0

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

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by sierrainfo
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.