Hi,
I am a beginner on using SQL Server Express. I have two different questions. Here is the first:
I've developed a simple C# application in Visual Studio 2005 that connects to a SQL Server database file. In the application I connect to the database using this connection string:
@."Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Databases\mydatabas.mdf ;Integrated Security=True;Connect Timeout=30;User Instance=True";
and It works perfect.
But when I move the database file(and the corresponding log-file) to another computer it fails. I've changed the connection string to this
@."Data Source=.\SQLEXPRESS;AttachDbFilename=\\myserver\Databases\mydatabase.mdf ;Integrated Security=True;Connect Timeout=30;User Instance=True";
This is the error message I get when I try to open the database
The file \\myserver\Databases\myDatabase.mdf is on a network path that is not supported for database files.An attempt to attach an auto-named database for file \\myServer\Databases\myDatabase.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
Both computer runs Windows XP SP2.
My second question is:
When I deployed my solution to my production PC(witch also runs Windows XP SP2, .NET Framwork 2.0 is installed on the computer) .When I then tried to run the application I did get this error message
An error has occured when establishing a connection to the server. When connection to a SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remomte conections.....
Appearently I cant treat SQL Server database files in the same way as Access-files, or?
Jan Olsson
To use the database on a different machine, SQLExpress would need to be installed on that machine (\\myserver) and the database attached there. Then you would connect to that SQL Server from your local machine. Use the "SQL Server Configuration Manager" to enable network connectivity. The AttachDBFilename really is only intended for local machine use.
SQL Server uses a client/server paradigm and you cannot treat SQL Server database files the same way as Access files.
|||In Access the runtime is in the database files SQL Server is RDBMS(relational database management systems) the runtime is in the server, there is a fixed location for the data files MDF and LDF log data files. They are located in the following location in your c drive, if you intend to use another location you must let SQL Server by code before creating the database. Hope this helps.
C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data
|||Thanks, for your good answer.
/Jan O.
|||Thanks Peter, I have installed SQL Server Express on my remote computer and attached my database file to SQL Server. it works properly. But how shall I connect to the database from my local machine? I tried to connect from Server Explorer in Visual Studio but it didn't work. I got the message "Login failed for user \\myserver\Guest" and if I want to connect from my C# application how shall the connection string look like.
Jan Olsson