Visual Studio causes error in SQL Management Studio - vb.net

This is my first try of Visual Basic 2010 Express, though I have 10 yrs+ experience in VBA.
I'm running Windows XP SP2 on a desktop pc with following installed:
Visual Basic 2010 Express... just installed!
SQL Server 205 Express ... been running on pc for 12 months
I've created a new DB in SQL for my test application, but have not added any users or permissions to it as I'm using Windows authentication.
I've created a new Windows Forms Solution in VB2010EXP and tried adding a new Data Source for my new SQL DB, but it keeps giving error message about not having rights ot the db.
2 days of searching on the web has confirmed many others with similar issues, but no obvious solution. Eventually I find a few threads about permissions and moving the mdf into the root of the HDD, so try moving my mdf file up closer to the root of the Hard Drive
msf was in C:\Documents and Settings\_SharedData\Application_Data\MSSQL2005\Data\
now in C:\SQL2005\Data\
Now I can finally add a data source to my Db and start to use VS.
Problem is now occasionally when I am workng in VB and then go to the SQL Management Studio and try and view/change my DB, it gives an error and I cant access my DB. I then have to detach and re attach to my DB before I can work on it.
So my questions are:
Surely the location of my MDF file
should not be critical???
Do I need to add a user and
permission to my DB or should VB be
able to deal with this automatically
as I'm using windows authentication
Are then any known issues with
VB/VS causing errors in SQL
Managment Studio?
Thanks in advance
Grant

SQL Server runs on a different Windows Account to the one you use. You can check this by going to services (Run > Services.msc) and under SQL Server, go to properties and the Log On tab. I think by default 2005 uses the 'Network Service' system account. Now the reason you can't attach an MDF sat inside your documents folder is that account doesn't have access to your documents. You could give it permission, but you're much better off having the databases closer to the root as you have done.
Your connection to the database is driven by the connection strings you use. My personal preference is to create SQL Login accounts for my applications, and give them the least possible permissions they require. You could do the same using a Windows Account if you prefer.
I'm sure there are a couple. What is the error you are getting that prevents you accessing the Db? If we can see this error we may be able to help better.
Hope that helps.

Related

Microsoft SQL Server Management Studio trouble with permissions

Please find all the files I'm refering to at this link:
http://whyisthisinmyfood.com/sql/
I have installed a new copy of "SQL Server 2008 R2 Management Studio Express (x86)" on two Windows 7 computers. The SAME install file for both computers. Installed the same way. (as far as I know, I chose the same options)
One at home and one at work.
The one at home seems to work perfectly I "Execute" this file (ITD132-Inventory Initial with data.sql) and it works fine. When I "Execute" it at work I get:
Msg 262, Level 14, State 1, Line 1
CREATE DATABASE permission denied in database 'master'.
..and a bunch of stuff after that which is caused because the database was not created in the first place.
I have compared the permissions on both computers.
see these files:
home computer : non-networked.jpg
work computer: work-networked.jpg
I read in one post that to create new Logins one must be logged in as the Administrator. I log into the Server Managment studio with my windows credentials and I am the Local Admin for my work computer and I have not been able to find any other place to log in as an administrator for this SQL Server Management Studio (so clearly I'm not sure whats meant by that)
At this point I think my problem is that I need to create a user who is not just the "BUILTIN\User" (because this login does not have permissions) with permissions.
But I have no idea how to login as an administrator to create this user role.
Please forgive me if these are obvious answers as I am just starting with this MS Management studio and am not very familiar with T-SQL.
Thanks,
Diana
If you install SQL Server, you get asked during installation process which user or user group should have the Admin-Privileges. If your computer is part of a domain and you login locally, things might get complicated.
The easiest (but not safest way) to login as a "superuser" if to enable the "sa" user.
this is one user that logs on with a password (not integrated logon) and has all the juice to run every script possible :-) By default it's disabled - googling I found a easy how-to enable it:
http://sudeeptaganguly.wordpress.com/2010/04/20/how-to-enable-sa-account-in-sql-server/
I think you are correct that you need to create another user with enough permission. Generally logging in with "integrated security" using your Windows credentials should have enough permissions (assuming the same user is the user that installed SQL Server). If not, you have better luck logging in as the SQL Server user "sa" (system administrator) which should have full permission. Do you know the "sa" password?
Note: the security mode for SQL Server can be set to "Only integrated security with Windows users", "SQL Server security" or "both". The "sa" account will only work if the SQL Server security is enabled. You may be able to access these settings using your BuiltIn\User account.

Cannot attach database SQL Server 2012 error 5

When I type this:
CREATE DATABASE AdventureWorks2012
ON (FILENAME = 'C:\Users\sohm\Desktop\Pohm\AdventureWorks2012_Data.mdf')
FOR ATTACH_REBUILD_LOG ;
I get this:
File activation failure. The physical file name
"C:\Users\sohm\Desktop\AdventureWorks2012_Data_log.ldf" may be incorrect.
Msg 5123, Level 16, State 1, Line 1
CREATE FILE encountered operating system error 5 (Access is denied.) while attempting to
open or create the physical file 'C:\adventuredb\AdventureWorks2012_Data_log.ldf'.
Msg 1813, Level 16, State 2, Line 1
Could not open new database 'AdventureWorks2012'. CREATE DATABASE is aborted.
I know it has to do with permissions. I have the administrator account. I have read a million posts but nothing has worked so far. Also when I try to change the folder containing the mdf file, to full control but it keeps reverting back to read-only.
You should run SSMS as an administrator.
Also it is possible that you might be running query as an 'sa' user(sql server authentication).
Try running the query with windows Authentication.
SHORT VERSION
For allowing MS SQL server 2012 to attach the database files you must grant full access to the mdf and ldf files to:
NT Service\MSSQLSERVER
Full Access
LONG VERSION
SQL Security has been updated a lot in 2012 handling of files.
http://technet.microsoft.com/en-us/library/ms189128.aspx
If you look at the existing attached databases and there security you will probably see that there only are 2 roles allowed with full access. MSSQLSERVER and Administrators, when attached SQL Removes all other roles from the files.
Trying to set the MSSQLSERVER from the fil security Permission will not work.
Looking at your services.msc overview you will in a default install see that NT Service\MSSQLSERVER also runs the SQL server servics.
The service account is not visible, the same issue as with IIS AppPools, a sub group has been created by the system and "hides" the accounts from auto discovery, probably to try and secure the accounts but in my view just obscures the setup.
Regards Jan
Open the SQL Server Management Stdio in Administrator mode(Right click -> Select Run as Administrator. If it asks for User name and password enter your Administrator user name password). Then select Windows Authentication click ok, and now try to attache it will attache without any error.
This has nothing to do with YOUR account. SQL Server is trying to write to that folder under the context of the service account that is running SQL Server. You can see who this is by going to the Services applet and seeing who the instance runs as (probably NT AUTHORITY\SYSTEM or whatever). You can override that or you can place your MDF files in the data folder, which SQL Server already has inherent access to, instead of placing them in this other location on your C:\ drive.
Another way to solve this is to change all the SQL Server services to Local System Account instead of services. Start -> Run ->Services.msc -> Scroll down to SQL Server, you should see five services that start with SQL Server. Right-Click, Properties, Log On, change to Local System Account. Repeat for all the rest of the SQL Server Services and restart them all.
Try This
Go to the folder where you have stored mdf file.
Select file -> Right click -> click on mdf give full permissions to file for logged in user Security.
If still issue persist and it might me because of corrupted transaction logs, you may use tool SQL Database Recovery Tool Repairs to repair your corrupted mdf file.
Figured it out. I went to sql server configuration manager and right clicked SQL Server Service. Then I added my Windows Admin account to run the service and now it works.

SQL Server Express unable to attach or delete mdf file

My database file Whist.mdf was attached to a SQL Server Express through Management Studio, but it stopped working in that sense that NHibernate in my asp.net solution fired some connection exceptions. I just detached it from Management Studio because I couldn't open the database in there either.
But when I try to reattach it I get this error:
Attach database failed for Server 'MyPCName\SQLECPRESS'. (Microsoft.SqlServer.Smo) Unable to open the physical file "C:\Program
Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\Whist.mdf".
Operating system error 32: "32(process cannot access the file because
it is being used by another process)". (Microsoft SQL Server, Error:
5120)
I have googled it but can't find a solution that works for me. E.g.:
http://www.byteblocks.com/post/2010/01/06/Unable-to-open-the-physical-file-Microsoft-SQL-Server.aspx
"Cannot open user default database. Login failed." after installing SQL Server Management Studio Express
There is something about User Instance but I cant figure out if it have anything to do with that:
http://blogs.msdn.com/b/sqlexpress/archive/2006/11/22/connecting-to-sql-express-user-instances-in-management-studio.aspx
I have tried to delete the mdf file in windows but I can't do that either:
The action can't be completed because the file is open in system
I have tried stopping the SQL Server process, closing explore and delete from cmd and rebooting...
Hope someone can help - I guess it is just a simple thing..
I think you are on the right track. The error messages you are getting indicate that some SQL Server process is keeping the database file open. And SQL Server is designed to only allow the database file to be open by a single SQL Server process at a time.
You are also probably right to suspect User Instance of SQL Server Express to be the guilty process here. User Instance is a special SQL Server process that doesn't run as a service and instead is started and owned by the application that tries to connect to it. In your case there are two User Instances that can be the problem, one owned by the ASP.NET application you mentioned and one owned by you and started by Visual Studio. If you are using IIS Express or you configured the IIS App Pool for the ASP.NET application to run as your account then we only have one User Instance to worry about.
My recommendation is that you don't use User Instances and don't try to connect directly to the database file. Go over your connection strings and remove User Instance=true from all of them. You want to remove AttachDBFilename=... property as well.
If the database file is added to any of your Visual Studio solutions remove it (just be careful not to delete the file itself). The last step is to remove any connections to the database file from your Data Connections node in the Server Explorer.
Then restart the machine to make sure any User Instances that were running in the background were shutdown. After the machine starts again you should be able to attach the database file back to your main SQL Server Express using SQL Server Management studio. Let's name the database Whist
To connect to your database use the following connection string:
Data Source=.\SQLExpress;Integrated Security=true;Initial Catalog=Whist
When you connect from the ASP.NET application, make sure that you have created an account in your SQL Server Express for the application.
Turned out to be an issue with Daemon tools for me as well associating the .mdf file as an image.
If you want to copy your .mdf and .ldf file from your database, you can set your database file to 'offline' first . Please follow this steps:
Open your SQL Server 2008(suppose you are using SQL Server 2008 ).
Select your Database that you want to copy then left click.
Go to Tasks -> Take Offline.
Right click.
Then you can copy this database file to any folders.

Migrating to SharePoint 2010

I was tasked to research migrating a 2007 MOSS to ShrePoint 2010. Got two servers, one is runing a SQL 2008, and the other has SharePoint 2010 already installed. I need to migrate several publishing and team sites and their corresponding databases. I started reading this article on Upgrade and Migration for SharePoint Server 2010
, then another at Migrate an existing server farm to a 64-bit environment but have a little confusion about wheather I'm migrating, upgrading, or moving the system, as each article defines steps to do this.
Current 2007 MOSS and SQL 2005 are on Windows 2003 32-bit OSs. The new system which at this point in not part of the farm but is in the same domain, are a 64-bit blades running Win 2008 OS with SQL 2008 and SharePoint 2010 - all already instaled / Central Admin site already running. The whole farm consists of 2 severs I just described.
Thanks for reading my post and appreciate any pointers!
Risho.
I just went through this exact scenario. The documentation on the various methods can get confusing. Note, for simple farms (no BDC, etc.), all you really need is the content databases. Here's a simple way to accomplish your goal:
On existing, 2007 farm, make sure it's Service Pack 2
On existing 2007 farm, run stsadm -o preupgradecheck
Fix any errors identified by the upgrade checker
Backup the Content database(s) you want to migrate (old 2007 farm)
Restore Content database(s) to new SQL server
Create a new Web Application on the new 2010 farm. A new WebApp will need to create a Content DB, so name it something like WSS_Content_Temp. This will be the WebApp that you will restore your Content to, so name the WebApp appropriately. You'll remove the content DB, so name it whatever you want.
From PowerShell, run: Test-SPContentDatabase -name <NameOfMovedContentDB> -webapplication http://yourNewWebApp
Fix any errors identified
From PowerShell, mount the newly restored/moved database. Run Mount-SPContentDatabases -name <NameOfRestoredContentDB> -webapplication http://yourNewWebApp. You should see a progress % number that is incrementing. Depending on how big your content databases are, this could take a while (30+ minutes)
From Central Admin -> Application Management, select/highlight your new Web Application.
The go back to Central Admin -> Manage Content Databases, and remove the original, temp Content DB (WSS_Content_Temp)
At this point, if all went well, you should be able to browse to http://yourNewWebApp and see all your content.
Rinse and repeat as needed.

Upgrading Sharepoint 3.0 to SQL 2005 Backend?

We're trying to get rid of all of our SQL Server 2000 databases to re purpose our old DB server... Sharepoint 3.0 is being a showstopper.
I've looked at a lot of guides from Microsoft and tried the instructions in those. I've also just tried the good ol' exec sp_detach_db / sp_attach_db with no luck. Has anyone actually done this?
my boss has. it was a real pain. permissions issues. he used the built in sharepoint backup tool. I can more details tomorrow if need. I'll check back.
I'm back. Here's the steps he used.
install an instance of sql server
2005 on the sql 2000 box
(side-by-side)
back up the sharepoint site using the sharepoint admin tools. This will create a one mother of a large xml file w/ the whole kit and kaboodle (the site & all it's content)
delete the old-n-busted sharepoint site
create a new hotness sharepoint site using the sql server 2005 as the database.
do a restore from the xml backup using the admin tools - this will take hours to run (thank you xml ...)
Bingo!
P.S. I forgot, the account you use to do the restore must be an 'sa' account.