Sync creating multiple subscription sqlcereplication - asp.net

I am currently developing a bridge between a database and a sql server database android (sqlite).
To do this, I use a web service and filtered replications with sqlce databases stored on a server IIS 7. To develop this, I used IIS Express on my pc. Everything works fine on my pc but when deployed, replicated databases create a new subscription for each synchronization (while on IIS Express sync works without creating a new subscription), no exceptions are thrown, nothing.
I don't understand why IIS 7 or IIS Express works in a different way to sync databases.
An idea of ​​the reason of the problem?
I use Sql replication ce 3.5 sp2, Sql server 2008 R2 as mother database, IIS7.
I tried to :
-Replicate motherdatabase with a little software on the webserver, it works.
-Use "SqlCeReplication.loadproperties" to find my sqlce database parameters to avoid the creation of the new subscription, it doesn't work.
Other details :
-When it is not syncing for the first time, webservices don't do "repl.AddSubscription(AddOption.CreateDatabase)", I already check that.
Here is the code used to sync :
' Define the server, publication, and database names.
Dim repl As SqlCeReplication = Nothing
Try
repl = New SqlCeReplication
repl.Publisher = PublisherName
repl.PublisherLogin = login
repl.PublisherPassword = password
repl.PublisherSecurityMode = SecurityType.DBAuthentication
repl.PublisherDatabase = My.Settings.DBName
repl.Publication = PublicationName
repl.InternetUrl = "https://iis.mydomain.com:444/sql/sqlcesa35.dll"
repl.InternetLogin = "sync"
repl.InternetPassword = "dfssd"
repl.Subscriber = "MobileApp - " & login
repl.SubscriberConnectionString = "Data Source=" & My.Settings.folderDB + "\" + subscriptionName + ".sdf"
If Not File.Exists(My.Settings.dossierBDD + "\" + subscriptionName + ".sdf") Then
repl.AddSubscription(AddOption.CreateDatabase)
End If
repl.Synchronize()
Catch err As SqlCeException
Finally
repl.Dispose()
repl = Nothing
End Try
Thanks in advance

I found myself the answer...
I don't really know why but if you want to do merge replication on sqlce, you will need to let the IIS website "Load the user profile" (on the application pool), otherwise subscription are created each time...

Related

SQL works in R studio but not in R-Serivces

This code works perfectly in R-Studio but there is no way to make it work in MS Management studio. It keeps on saying that:
[Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'myserver\LOCAL01'.
That is not my user give it is a trusted connection. Can someone help me understand it?
ALTER PROCEDURE [dbo].[TESTIM] AS
BEGIN
SET LANGUAGE ENGLISH
CHECKPOINT 
DBCC DROPCLEANBUFFERS
EXEC sp_execute_external_script
#language = N'R'
, #script = N'
con <- "Server=myserver\\LOCAL;Database=mydb;Trusted_Connection=true";
sql <- RxInSqlServer(connectionString = con, shareDir = "c:\\TMP");
local <- RxLocalSeq(sql);
rxSetComputeContext(local)
ff <- RxSqlServerData(sqlQuery = "select top 1 * from mytable", connectionString = con);
t = rxImport(ff);
OutputDataSet <- data.frame(SUCCESS = TRUE);
'
WITH RESULT SETS (([SUCCESS] BIT))
END
So, when you execute sp_execute_external_script it executes under one of 20 Windows user accounts (worker accounts) that has been created during installation of SQL Server R Services. These accounts are created for the purpose of running tasks under a security token belonging to the SQL Server Trusted Launchpad service.
This works very well, but if you need to create a SQL connection inside your R script (as in your case) and you use trusted connection (Windows Authentication), you are executing under the user account mentioned above ('myserver\LOCAL01' in your case), and that account need to be given permission to log in to the SQL Server instance on your behalf.
To do this:
In SQL Server Management Studio, in Object Explorer, expand Security, right-click Logins, and select New Login.
In the Login - New dialog box, click Search.
Click Object Types and select Groups. Deselect everything else.
In Enter the object name to select, type SQLRUserGroup and click Check Names.
The name of the local group associated with the instance's Launchpad service should resolve to something like instancename\SQLRUserGroup. Click OK.
By default, the login is assigned to the public role and has permission to connect to the database engine.
Click OK.
That should do it (the above steps are copied from here.
If you want to read more about the user accounts you can have a look at my blog-post "Microsoft SQL Server R Services - Internals III".
Hope this helps!
Niels

Transaction not connected when the app is called from a website

I have a PowerBuilder.net console application that uses SQLNCLI10 to connect a SQL Server 2008 R2. This applications needs to be executed from a ASP.NET MVC website hosted in the same server, and its output readed.
This is the code for executing the application on the MVC:
var proc = new System.Diagnostics.Process
{
StartInfo = new System.Diagnostics.ProcessStartInfo
{
FileName = ConfigurationManager.AppSettings["PB_EXE"],
Arguments = Credentials.ClientId + " " + reference,
UseShellExecute = false,
RedirectStandardOutput = true,
WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden
}
};
When the application is executed from the MVC, the PBTransaction objects returns the generic "Transaction not connected" sql error.
The thing is, the application runs well with a .bat that call the executable with parameters. Even more, a simple WinForms using the same code above, gets the transaction connected successfully.
I have alredy tried setting the ApplicationPool of the website to the administrator of the server, with the same results.
What I'd check first to solve connectivity issues on a PB.NET console application.
Putting some logging into the console application and examine the Transaction object immediately before and after attempting the connection. It will likely provide necessary information to identify the culprit.
Make sure PowerBuilder database connectivity run-time libraries (e.g. PBORA010.DLL) are installed on the server and accessible to the role running the application.
If the connection uses ODBC/JDBC make sure any DSNs needed on server are accessible to the console application.

SSAS Error The MyCube either does not exist or has not been processed when attempting to query through ASP.NET

I have a cube, which has been processed, works from the BID environment, and I can run my MDX query in both SSEM, and the BID env. I've created a role that contains the proper accounts/permissions, processed, and deployed the cube, re-processed it in SSEM, etc. Now I'm trying to connect, and extract the data using ASP.NET 4.0, but I'm getting this error:
The MyCube either does not exist or has not been processed
Here's my code:
String connectionString = "Provider=MSOLAP.3; Data Source=myhost;Initial Catalog=myCatalog; User ID=myaccount; Password=myamazinglysecurepassword;";
String mdxSQL = " my MDX, which was taken directly from BID env. cube in design mode";
AdomdConnection connection = new AdomdConnection(connectionString);
connection.Open();
AdomdCommand cmd = new AdomdCommand(mdxSQL, connection);
CellSet cst = cmd.ExecuteCellSet();
...etc
Note: we are not using MSMDPUMP.dll to connect, we'd like to avoid that.
Any Ideas?
A couple things to consider. How are users authenticating to your web app? What account is your application pool running as?
If you're using Integrated Windows in ASP.NET you may be getting a double-hop issue if IIS and SSAS on different servers. This would require you to set up Kerberos and trusted delegation SPN's between your application and the OLAP service.
See (SSAS and IIS):
http://msdn.microsoft.com/en-us/library/dn194199.aspx
http://technet.microsoft.com/en-us/library/dd632778.aspx
Otherwise there may be an issue with the account your application pool is running under. I see in your connection string you have a specific account - so I presume you are trying to connect as one account rather than delegating user credentials to OLAP. The process running w3wp.exe is the identity which will attempt to connect to SSAS. If your application pool is not runnning as a domain account is may not be able to authenticate to SSAS.

Cannot bulk load because the file could not be opened. Operating system error code 21(The device is not ready.)

Cannot bulk load because the file could not be opened. Operating system error code 21(The device is not ready.).
Hi All,
I am a newbie to Image Upload in MS SQL Server using ASP.NET. its cool to upload a image in a query from the same machine as the server but when from a remote machine ASP.NET web application to MS SQL Server, I am getting the above mentioned error.
I don't understand what needs to be done, i have seen several threads and forums but i am not able to understand, can you please help me out on the same. I am looking for some descriptive steps to fix this issue.
Session["FileName"] equals some d drive file
Query I use:
command.CommandText = "UPDATE user_info "
+ "SET User_Image = (SELECT * FROM Openrowset(Bulk '" + Session["FileName"] + "', Single_Blob) AS User_Image) "
+ "WHERE id =" + "22222";
I use SQL Authentication
I have enabled both named pipes + TCP/IP
if EXECUTE AS is to be used, can someone explain the query. Is there any setting that need to be enabled. I am desperate :(
Thanks in advance !
I know this is old question, but it might help someone else in doubt.
To use bulk, file needs to be on the server.
This means you need to upload file from client machine to the server before using bulk.
1) get the name of the account sql server is running
2) go to the folder in your Session["FileName"] equals some d drive file
3) give permissions on that folder to the sql server account to read write permissions

How can I create a database on my server from the web?

I have an admin account for my website where I add new clients. When a new client is added, they get an account and their own database.
The problem is I can't create new databases on my server from my admin account. When running it locally, I can add a database locally. But, when I try adding to the server running my website off the server, I get
CREATE DATABASE permission denied in database 'master'.
I've been able to add the database (locally) a few ways. This is one of the simpler working versions:
tmpConn.ConnectionString = "Data Source=.\\SQLEXPRESS; DATABASE = master;Integrated Security=True;";
sqlCreateDBQuery = " CREATE DATABASE " + dbname;
SqlCommand myCommand = new SqlCommand(sqlCreateDBQuery, tmpConn);
try
{
tmpConn.Open();
myCommand.ExecuteNonQuery();
}
catch (System.Exception ex)
{}
I suspect that whatever account you're using to connect to Sql Server doesn't have permissions to CREATE DATABASE. You're probably using Integrated Security, which would use Network Service/ASP.NET to connect to MSSQL. You need to create a new connection string that uses Sql Authentication with sa (or another sysadmin) credentials.
Oh - and this would work locally because you're running it under Visual Studio's WebDev.exe which is run with your local user account - which is probably set up as a sysadmin in MSSQL.
You should contact your service provider. (Or the maintainer of the server).
You need create database and create database user permissions. Your service provider should be able to facilitate this.
Something else no one has suggested is what kind of validation you are doing on the dbname value. Are you sure there are no spaces in it? That it's not a reserved word? That it doesn't contain malicious code? At very least you should encase it in brackets:
sqlCreateDBQuery = String.Format(" CREATE DATABASE [{0}]", dbname);
I really hope you aren't allowing the user to type this name directly into a textbox somewhere. Even if you use property security on the initial input and this is pulled back from a common "clients" db of some kind, you might be setting yourself up for a 2nd order Sql Injection vulnerability.
After you've addressed that, we can look at the error message here. In this case, the problem is that your web user does not have appropriate CREATE permissions. You need to correct that and it should allow you to proceed. You probably want to reserve a special account for this that you switch to just at this time, so your application doesn't normally run in a context that would allow this kind of action.
Check the permissions for MySQL: Does your admin account have different settings for a local connection versus any host?

Resources