I'm using C# Express and SQL Server Express. I can connect to sample databses I have downloaded to the default location (..\MMSQL.1\MSSQL\DATA) but I cannot connect to a new database I create using SQL Server. The error is "You don't have permission to open this file. Contact the owner or administrator to obtain permission". I'm the owner, of course.

I can create a new database directly in a C# project and put it together, but I cannot see it from SQL Server.

I can connect to Access databases without any problems.

Is this a limitation built into C# Express and SQL Explorer Express because they are essentially free samples, or am I missing something obvious?

There are a few things for you to look at.
Where the databases created using the "sa" administrator account ? IOW, who is the owner of the database, and was the Login account you are using to log in to the server have permission to use the new DB.

The error you are getting is strictly an SQL error. Has nothing to do with C#. Post the code you are using to attach the database, assign permissions, and then connect, and someone will help.

I am not directly using SQL, but I assume the C# environment is. I am from a Delphi/Access environment. C# has been no problem but SQL Server has proved a puzzel. I will try to give an exact description of what I am doing:

In SQL Server Express
Right-click Databases and create a new one.
In the NewDatabase dialog, Owner is set to <default>.
Check for other owners. In Select Database Owner dialog, there are no objects listed. Do I need to create a user first?
Create the new database using Owner of <default>, create a new table and run a select query. No error, and the results pane displays the fields from the table. So I assume I am properly connected in SQL Server.

Go to C# Express, create a new project and use Data | Add new data source wizard. In the connection dialog, click the New connection button. In the Add connection dialog Data source is set to Microsoft SQL Server Database File (SqlClient), use Windows authentication, navigate to the database, and select it. I get the error listed in my first post. I have also tried using SQL Server Authentication with my usual passwords.

I too am from the Delphi world. Have you tried using Delphi to access this database ?
As a test, can you see if you can access the database through code.

private void Form1_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=SHAWHP\\SQLEXPRESS;Initial Catalog=SoftwareInventory;Integrated Security=True";
conn.Open();
conn.Close();
}

Finally, what does your connection string look like ?
In the above sample code, replace the SHAWHP\\SQLEXPRESS
with your own server, and the SoftwareInventory catalog with your
own and see if that works.

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.