User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C# section within the Software Development category of DaniWeb, a massive community of 456,589 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,593 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C# advertiser: Programming Forums
Views: 4065 | Replies: 3
Reply
Join Date: Aug 2007
Location: Gunnison, Colorado
Posts: 57
Reputation: fishsqzr is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
fishsqzr fishsqzr is offline Offline
Junior Poster in Training

Question Problem connecting to SQL Server Express

  #1  
Oct 30th, 2007
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?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2006
Location: Bonners Ferry, ID
Posts: 280
Reputation: JerryShaw is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 39
JerryShaw JerryShaw is offline Offline
Posting Whiz in Training

Re: Problem connecting to SQL Server Express

  #2  
Oct 31st, 2007
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.
Reply With Quote  
Join Date: Aug 2007
Location: Gunnison, Colorado
Posts: 57
Reputation: fishsqzr is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
fishsqzr fishsqzr is offline Offline
Junior Poster in Training

Re: Problem connecting to SQL Server Express

  #3  
Oct 31st, 2007
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.
Reply With Quote  
Join Date: Nov 2006
Location: Bonners Ferry, ID
Posts: 280
Reputation: JerryShaw is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 39
JerryShaw JerryShaw is offline Offline
Posting Whiz in Training

Re: Problem connecting to SQL Server Express

  #4  
Oct 31st, 2007
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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C# Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C# Forum

All times are GMT -4. The time now is 6:41 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC