I am unable to find the name space for the SPSite
I have imported these so far:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using Microsoft.SharePoint;
using System.Collections;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint;
using System.Data.SqlClient;
using SP = Microsoft.SharePoint.Client;
using System.Data;
namespace GrandPermission
{
class Program
{
static void Main(string[] args)
{
SPSite oSPSite = new SPSite("http://spdevserver:1002/");
}
}
}
And SPSite still has red line under it.
This error occurs since SPSite class is a part of Server Side Object Model API:
Server Side Object Model API could be utilized only on machine where SharePoint Server/Foundation is installed.
Since you are using Client Object Model API (referenced assembly in your project Microsoft.SharePoint.Client.dll is a part of SharePoint Server 2013 Client Components SDK) i would recommend to utilize this API.
So, the line:
SPSite oSPSite = new SPSite("http://spdevserver:1002/"); //SSOM
could be replaced with:
using(var ctx = new ClientContext("http://spdevserver:1002/"))
{
var site = ctx.Site;
//...
}
References
Choose the right API set in SharePoint 2013
Based on your screenshot, you are missing a reference to Microsoft.SharePoint in your project's references. You only have a reference to the client dll.
If you're not finding it, make sure you're either developing on a SharePoint server, i.e. SharePoint is installed, or have a copy of the dll on your machine. I've seen forum posts where someone copied the SharePoint dll from a SharePoint server to a local non-SharePoint development machine. However, I've never gotten that to work. I've always installed SharePoint on a development server and ran Visual Studio from it.
You need to add the assembly Microsoft.SharePoint.dll into your references in order to use it. You can find this DLL on the SharePoint server that you're working with:
On SharePoint 2013 it lives at:
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI
And on SharePoint 2010 it can be found at:
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI
Related
The type or namespace name 'Server' could not be found (are you missing a using directive or an assembly reference?)
string connetionString = #"connectionStirng";
SqlConnection conn = new SqlConnection(connetionString);
var server = new Server(new ServerConnection(conn));
added at the top
using Microsoft.SqlServer.Management.Common;
Still giving error.
Any help appricated.
Already checked:
Why i'm getting error for the Microsoft.SqlServer.Server namespace?
I can't add Microsoft.SqlServer.Management.Common to my ASP.NET MVC Application
Install this nuget package:
https://www.nuget.org/packages/Microsoft.SqlServer.SqlManagementObjects
Then add using directive:
using Microsoft.SqlServer.Management.Smo;
Now you can create Server object.
var server = new Server();
Installing SMO
Beginning with SQL Server 2017 SMO is distributed as the
Microsoft.SqlServer.SqlManagementObjects NuGet package to allow users
to develop applications with SMO.
This is a replacement for SharedManagementObjects.msi, which was
previously released as part of the SQL Feature Pack for each release
of SQL Server. Applications that use SMO should be updated to use the
NuGet package instead and will be responsible for ensuring the
binaries are installed with the application being developed.
https://learn.microsoft.com/en-us/sql/relational-databases/server-management-objects-smo/installing-smo?view=sql-server-2017
As suggested by Han, Please check the assembly reference path and make sure that the file is there at the referenced location. I had faced similar problem, this was working on the Development environment but error on test server. The reason was the SQL Server Management studio was not installed on the Test server. So i copied the required Assemblies from dev machine to bin folder of the application on test server and that worked.
Can you try adding a reference to:
Microsoft.SqlServer.dac.dll
If cant find the dll, then need to install SSDT (Sql Server Data Tools).
I am trying to migrate a .Net 4.5.2 application from using Microsoft's deprecated System.Data.OracleClient dll to using Oracle's own Oracle.ManagedDataAccess.dll (using the Nuget package v12.1.1.24160419). On the machine in question I have the Oracle client installed, and I have a tnsnames.ora file set up which the original app successfully uses to connect. I can also successfully connect with Oracle's SqlPlus and SqlDeveloper tools. However if I try to use the Oracle dll my application cannot connect.
To distill this down to the very basics I have created a very simple console application (code below) to see what is going on. If the project references the Microsoft dll (with the appropriate using statement) it will connect, but if instead I reference the Oracle.ManagedDataAccess.dll (with the appropriate using statement) it complains about a TNS error:
ORA-12504: TNS:listener was not given the SERVICE_NAME in CONNECT_DATA
I've tried adding a SERVICE_NAME clause to the tnsnames.ora file but with no improvement.
What else do I need to do?
Test app is:
using Oracle.ManagedDataAccess.Client;
using System;
using System.Collections.Generic;
//using System.Data.OracleClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace oracleconnect
{
class Program
{
static void Main(string[] args)
{
try
{
InitializeDBConnection();
}
finally
{
if (_con.State==System.Data.ConnectionState.Open)
_con.Close();
}
}
static private OracleConnection _con;
private const string connectionString = "Data Source=oracledbserver2;User ID=MATTESTNHSYS;Password=thePassword";
private static void InitializeDBConnection()
{
_con = new OracleConnection();
_con.ConnectionString = connectionString;
_con.Open();
}
}
}
Oracle.ManagedDataAccess.dll has a different search pattern to find your tnsnames.ora file. Unlike System.Data.OracleClient or SQL*Plus Oracle.ManagedDataAccess.dll does not read TNS_ADMIN value from Registry or Environment variable.
See Oracle Data Provider for .NET, Managed Driver Configuration
data source alias in the dataSources section under <oracle.manageddataaccess.client> section in the .NET config file (i.e. machine.config, web.config, user.config).
data source alias in the tnsnames.ora file at the location specified by TNS_ADMIN in the .NET config file. Locations can consist of either absolute or relative directory paths.
data source alias in the tnsnames.ora file present in the same directory as the .exe.
Data Source should be defined like this:
Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=type_hostname)(PORT=type_port))(CONNECT_DATA=(SERVICE_NAME=type_service_name_from_tsnames)))
And the connection string like:
private const string connectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=type_hostname)(PORT=type_port))(CONNECT_DATA=(SERVICE_NAME=type_service_name_from_tsnames)));User ID=MATTESTNHSYS;Password=thePassword";
I know this error maybe very popular and there are many people asking about it. I have read through other threads but can not seem to find a solution applicable to my scenario.
I am new to ASP.NET programming, am using vs 2013 ultimate, IIS express on my laptop with Windows 8.1.
I have created a new website using WebForms and I was testing the upload function to my local machine running IIS express that came with VS2013.
My code behind is as simple as
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class MyWebForm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
string name = TextBox1.Text;
string type = DropDownList1.SelectedValue;
string filename = FileUpload1.FileName;
FileUpload1.SaveAs(Server.MapPath("~/Content"));
}
}
}
Ran it and got this error:
{"Access to the path 'C:\\Users\\xxx\\Documents\\Visual Studio 2013\\WebSites\\WebFormDemo\\Content' is denied."}
I understand that it is an unauthorized access due to lack of privilege, but my question is how do I give access to my application? I have admin right on my machine, run it locally so the firewall should not be an issue. Some threads suggested to go to IIS manager and adjust the right to DefaultPool but I do not think I have InetMgr on my Windows 8.1,
How do I solve the unauthorized access for my case?
I want to teke backup of database in windows forms application.
I have added References to all 4 ddls
Microsoft.SqlServer.ConnectionInfo.dll
Microsoft.SqlServer.Management.Sdk.Sfc.dll
Microsoft.SqlServer.Smo.dll
Microsoft.SqlServer.SmoExtended.dll
My Code is
using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SqlServer.Server;
using Microsoft.SqlServer.Management.Sdk.Sfc;
using Microsoft.SqlServer.Smo;
using Microsoft.SqlServer.Smo.SmoExtended;
namespace Lodging
{
class BackupAndRestoreData
{
public static void BackupDatabase(string backUpFile)
{
ServerConnection con = new ServerConnection(#"ANI-PC\SQLEXPRESS");
Server server = new Server(con);
Backup source = new Backup();
source.Action = BackupActionType.Database;
source.Database = "db_Lodge";
BackupDeviceItem destination = new BackupDeviceItem(backUpFile,
DeviceType.File);
source.Devices.Add(destination);
source.SqlBackup(server);
con.Disconnect();
}
public static void RestoreDatabase(string backUpFile)
{
ServerConnection con = new ServerConnection(#"ANI-PC\SQLEXPRESS");
Server server = new Server(con);
Restore destination = new Restore();
destination.Action = RestoreActionType.Database;
destination.Database = "MyDataBaseName";
BackupDeviceItem source = new BackupDeviceItem(backUpFile,
DeviceType.File);
destination.Devices.Add(source);
destination.ReplaceDatabase = true;
destination.SqlRestore(server);
}
}
}
This is not giving me error for
using Microsoft.SqlServer.Server;
using Microsoft.SqlServer.Management.Sdk.Sfc;
but gives error :
The type or namespace name 'Smo' does not exist in the namespace 'Microsoft.SqlServer' (are you missing an assembly reference?)
for
using Microsoft.SqlServer.Smo;
using Microsoft.SqlServer.Smo.SmoExtended;
What should I do to remove this error?
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;
Try this two namespaces.
The Microsoft.SqlServer.Management.Smo namespace contains the instance
object classes that represent SQL Server Database Engine objects and
some utility classes that represent specific tasks, such as scripting.
When a connection to the instance of the SQL Server Database Engine
has been established by using a Server object variable, objects on the
instance can be accessed by using the SMO instance objects. For
example, you can use the Database object to access databases on the
connected instance of SQL Server Database Engine. All the instance
classes are related to the Server class in the object hierarchy.
Utility classes exist outside of the Server class object hierarchy and
represent specific tasks, such as backup or scripting.
Here is link to the article in MSDN
Common is also widely used I recommend you to read about it.
Not sure if this help you, but for the compile error:
The type or namespace name 'XYZ' does not exist in the namespace
'ABC.DEF' (are you missing an assembly reference?)
I found following reasons causing that complation error:
1) If the assembly is targeting later .NET framework(e.g. 4.5) and you refer the assembly from an application targeting early .NET framework (e.g.4.0) then you may face this problem.
2) Some times, the "Client Profile" .NET framework projects can't refer to full .NET version assemblies, because Client Profile .NET framework is a strip-down version of .NET framework.
Install SMO
The SQL Server Management Objects (SMO) Framework is a set of objects designed for programmatic management of Microsoft SQL Server and Microsoft Azure SQL Database.
When explicitly targeting a pre-2017 SQL Server version, install the SQL Server Feature Pack (more info in this answer).
For SQL Server 2017 and above, install SMO as a NuGet package, as per this answer.
The following code breaks in a .NET 3.5 class library project, but not in .net 4. I'm stumped and would appreciate any ideas:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using NUnit.Framework;
namespace test2
{
[TestFixture]
public class TestClass
{
[Test]
public void Test()
{
var request =
WebRequest.Create("http://www.google.com");
Specific Exception:
System.Security.SecurityException : Request for the permission of type 'System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
at System.Security.CodeAccessSecurityEngine.Check(Object demand, ref StackCrawlMark stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at System.Net.HttpWebRequest..ctor(Uri uri, ServicePoint servicePoint)
at System.Net.HttpRequestCreator.Create(Uri Uri)
at System.Net.WebRequest.Create(Uri requestUri, Boolean useUriBase)
at System.Net.WebRequest.Create(String requestUriString)
at test2.LaunchRequestInitializeIdsTestFixture.Test()
The answer, as the exception says, is Code Access Security (CAS). I am building my code from a network drive (hosted VM). In .NET 3.5 and below, the network drive has lower privileges. This restriction was turned off for .NET 3.5 SP1 and above. The following link put me on the right track:
http://blogs.msdn.com/b/vancem/archive/2008/08/13/net-framework-3-5-sp1-allows-managed-code-to-be-launched-from-a-network-share.aspx
The following, run from caspol in the .NET 2 install dir got my code working:
caspol.exe -m -pp off -ag 1 -url "file:///Z:/*" FullTrust
I got the above command line from this helpful post:
https://julianscorner.com/wiki/programming/caspol_network_share
FYI:
to restore to defaults, just run "caspol -restore"