Creating backup of my .mdf DB file during runtime - c#-4.0

when i try to use this code for creating backup of my DB this error occures ?
Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
dlg.ShowDialog();
File.Copy(#"C:\Program Files\Microsoft SQLServer\MSSQL10.MSSQLSERVER\MSSQL\DATA\MyDB.mdf", dlg.FileName );
The process cannot access the file 'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\MyDB.mdf' because it is being used by another process.

Related

The type or namespace name "ContentBySearchWebPart" could not be found

Recently, I was trying to add a Content Search Web Part using csom in Visual Studio 2017, While I was adding the "ContentBySearchWebPart" class, an error occured as:
"The type or namespace name "ContentBySearchWebPart" could not be found(you are missing a using directive or an assembly reference?)".
Even I was using the namespace as "Microsoft.Office.Server.Search.WebControls" and also the "Microsoft.SharePoint.Client.Search" dll.
How can I resolve this issue?
You need to add reference "Microsoft.Office.Server.Search.dll" manually from ISAPI folder or GAC
ISAPI folder
<Windows>\Program Files\Common Files\Microsoft Shared\Web Server Extenstions\16\ISAPI
GAC
(C:\windows\Windows.NET\assembly\GAC_MSIL\Microsoft.Office.Server.Search).
Namespace: Microsoft.Office.Server.Search.WebControls
Assembly: Microsoft.Office.Server.Search (in Microsoft.Office.Server.Search.dll)
https://social.msdn.microsoft.com/Forums/sharepoint/en-US/c6f03ea3-f893-4126-88e3-52a2a66b5f18/missing-assembly-reference-for-microsoftofficeserversearch?forum=sharepointdevelopmentprevious
Check your \Program Files\Common Files\Microsoft Shared\Web Server Extenstions\14\ISAPI, you'll find alot more DLL's inside this folder including your Microsoft.Office.Server.Search.dll that you are looking for.

Sharepoint 2013 GetGenericSetupPath return wrong path

I'm tring to obtain file path for sharepoint 2013 location without hardcoding values on code.
I found the method GetGenericSetupPath,SPUtility class, wich has a strange behaviuor:
SPUtility.GetGenericSetupPath("Template")
reuturns
"C:\Program Files\Common Files\Microsoft Shared\Web Server
Extensions\15\Template"
on the 15 hive
inhstead
SPUtility.GetGenericSetupPath("template\\LAYOUTS")
return a path on 14 hive
"C:\Program Files\Common Files\Microsoft Shared\Web Server
Extensions\14\template\LAYOUTS"
finally the default path seems to be hive 15:
SPUtility.GetGenericSetupPath("")
"C:\Program Files\Common Files\Microsoft Shared\Web Server
Extensions\15\" string
After some investigation i found this post:
The problem was that
SPUtility.GetGenericSetupPath Method IS OBSOLETE
and it returns a link to the 14 hive (SharePoint 2010), not the the new 15 hive (SharePoint 2013).
Instead of this we have to use SPUtility.GetVersionedGenericSetupPath(), where you can choose wich version of sharepoint use, so you can specify:
SPUtility.GetVersionedGenericSetupPath("TEMPLATE\\FEATURES", 15)

SharePoint 2013 default favicon

I want to change the default favicon on my SharePoint site. I didn't want to change the masterpage, so I just replaced the favicon.ico file with the one I created (.ico) here: C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\IMAGES. It still shows the default favicon even after I did iisreset. I would appreciate any suggestions / help. Thank you!
I made it work by uploading the generated favicon to [site]/SiteAssets/Forms/AllItems.aspx and then changing the following line in the master page: < SharePoint:SPShortcutIcon runat="server" IconUrl="[site]/SiteAssets/[your_favicon_name].ico" />.
Changing favico must be done by
Change the icon, as you suggested, in C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\IMAGES
Empty any browser cache
Empty the IIS Temporary Cache if you have compression enabled C:\inetpub\temp\IIS Temporary Compressed Files\
(full path is C:\inetpub\temp\IIS Temporary Compressed Files\SharePoint Central Administration v4\$^_gzip_C^\PROGRAM FILES\COMMON FILES\MICROSOFT SHARED\WEB SERVER EXTENSIONS\15\TEMPLATE\IMAGES)
Stop IIS and emtpy the temporary internet files, Start IIS
Run in PowerShell to delete Temporary ASP.NET Files
net stop w3svc
Remove-Item -Path "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\*" -Force -Recurse
Remove-Item -Path "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\*" -Force -Recurse
net start w3svc

After installing SQL Server Express 2008 R2 using SQLEXPRWT_x86_ENU.exe, SQL Server can't create database

I have an NSIS install script which successfully installs an instance of SQL Server Express 2008 R2 on Windows 7, but when I later try to create a database from the install script I get an error saying access denied. My detailed steps follow.
I install SQL Server Express with my NSIS installer using the following:
ExecWait 'SQLEXPRWT_x86_ENU.exe /Q /ACTION=Install /IACCEPTSQLSERVERLICENSETERMS /ROLE=AllFeatures_WithDefaults /SQLSVCACCOUNT="NT AUTHORITY\Network Service" /INSTANCENAME=SQLXXXX /SecurityMode=SQL /SAPWD="xxxxxx" /IndicateProgress'
Then within my NSIS installer I 'try' to create a database with the following:
ExecWait 'sqlcmd -S "computerName\SQLXXXX" -i "$OUTDIR\ASPNETDB_Create.SQL" -o "$OUTDIR\ASPNETDB_Create_Log.txt"'
The script ASPNETDB_Create.SQL fails at the first command in it which follows:
CREATE DATABASE [aspnetdb] ON PRIMARY
( NAME = N'aspnetdb', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLXXXX\MSSQL\DATA\aspnetdb.mdf' , SIZE = 411392KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
LOG ON ( NAME = N'aspnetdb_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLXXXX\MSSQL\DATA\aspnetdb_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO
I get the following error listed:
CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLXXXX\MSSQL\DATA\aspnetdb.mdf'.
It seems the problem is that the folder 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLXXXX\MSSQL\DATA' doesn't have any permissions set for user "NT AUTHORITY\Network Service".
If incorrect access permissions are indeed my problem, how can I set the correct permissions on the DATA directory where the database will reside?
You can change the ACL with the AccessControl plugin

Strong Named satellite assemblies using ResGen & AL with multiple resx / resources files

For whatever reason, when compiling multiple .resources files into a single satellite assembly (.dll) the resources will not show. Compiling a single resource will work. Here are the steps I used...
We have a project called "Report Viewer". This project is signed using a key, MySnKey.snk via Properties > Signing > Sign the assembly , choose a strong name key file: MySnKey.snk.
All forms have been updated to Localizable = True
We processed all the resx files into German de-DE. There are only two resx: MainForm.resx (project root directory) and Resources.resx (Properties directory).
I have a folder with MainForm.de-DE.resx and Resources.de-DE.resx which are the translated versions of these files.
Using resgen,
> "C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\ResGen" /compile Resources.de-DE.resx ReportViewer.Resources.de-DE.resources
> "C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\ResGen" /compile MainForm.de-DE.resx ReportViewer.MainForm.de-DE.resources
This creates the appropriate .resources files. Now to link, I use AL.exe:
> "C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\AL" /t:lib /embed:ReportViewer.MainForm.de-DE.resources,ReportViewer.Resources.de-DE.resources /culture:de-DE /out:ReportViewer.resources.dll /template:../../../Output/ReportViewer/bin/Debug/ReportViewer.exe /keyfile:../MySnKey.snk
This creates a ReportViewer.resources.dll file. If I place it into the appropriate sub folder de-DE>ReportViewer.resources.dll, no luck. In Program.cs, before Run is called, I have
Thread.CurrentThread.CurrentUICulture = new CultureInfo("de-DE");
IF, I only include the MainForm like
> "C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\AL" /t:lib /embed:ReportViewer.MainForm.de-DE.resources /culture:de-DE /out:ReportViewer.resources.dll /template:../../../Output/ReportViewer/bin/Debug/ReportViewer.exe /keyfile:../MySnKey.snk
The appropriate resources are displayed.
This is quite confusing to me. If I add the .resx files to the solution, and compile, the output dll works correctly, but we are trying to avoid having to bring these satellite translations into the solution.
No errors are generated and the files are created so I'm lost as to what I'm not doing.
Any help is greatly appreciated. I compared the differences between the output dll when adding the files to the solution to the output file when running AL.exe and they both contain all the translations.
EDIT to include solution since I can't answer the question
Apparently I got confused with the embed option and it's usage. To properly use the AL.exe utility, I had to use:
> "C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\ResGen" Resources.de-DE.resx ReportViewer.Properties.Resources.de-DE.resources
Notice above that the Properties namespace is added. I had not done that before.
> "C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\ResGen" MainForm.de-DE.resx ReportViewer.MainForm.de-DE.resources
Notice that no Properties namespace is added since MainForm is Simply in the ReportViewer namespace.
> "C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\AL"
/t:lib
/embed:ReportViewer.Properties.Resources.de-DE.resources
/embed:ReportViewer.MainForm.de-DE.resources
/culture:de-DE /out:ReportViewer.resources.dll /template:../../../Output/ReportViewer/bin/Debug/ReportViewer.exe /keyfile:../MySnKey.snk
Notice that there are multiple /embed items in this line. I was using the comma, which renames the internals and is not what I wanted. Providing a space between the files gives a (seemingly) unrelated error. See http://ondotnet.com/pub/a/dotnet/2002/10/14/local2.htm?page=2 for a great article.
For completeness, another way of writing this script would be
> "C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\ResGen" Resources.de-DE.resx
notice that no renaming is done here, the output is simply Resources.de-DE.resources
> "C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\ResGen" MainForm.de-DE.resx
notice that no renaming is done here, the output is simply MainForm.de-DE.resources
> "C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\AL" /t:lib
/embed:Resources.de-DE.resources,ReportViewer.Properties.Resources.de-DE.resources
/embed:MainForm.de-DE.resources,ReportViewer.MainForm.de-DE.resources
/culture:de-DE
/out:ReportViewer.resources.dll /template:../../../Output/ReportViewer/bin/Debug/ReportViewer.exe /keyfile:../MySnKey.snk
Notice that the renaming is done following the comma in the embed option. The first argument is the file name (the .resources file) and after the comma is the fully qualified name (namespace.class.xx-XX.resources).
Answered in the post before I knew I could answer it here.

Resources