I always had a working version in Azure but somehow it does not work anymore, I copied the database and I created new connections. When I run in localhost all works fine, however when I publish it does not work anymore, unless I delete the analytics section of the REST
this is what I got:
// GET PROGRAM (IF EXIST)
[Route("api/Program/{ProgramCode}/{id_user}/{id_client}")]
public object GetProgramSettingsFromFile(string ProgramCode, string id_user, int id_client)
{
AnalyticsUser newEntry = new AnalyticsUser
{
id_user = id_user,
ProgramCode = ProgramCode,
DateTime = DateTime.Now,
id_client = id_client
};
db.AnalyticsUsers.Add(newEntry);
db.SaveChanges();
string secondPart = "api/program/" + ProgramCode + ".json";
var allText = (new WebClient()).DownloadString(uriPath + secondPart);
object jsonObject = JsonConvert.DeserializeObject(allText);
return jsonObject;
}
the above works fine in local host, but when published it does not work. Error 500 internal server error. So when i escape the analytics section like this:
// GET PROGRAM (IF EXIST)
[Route("api/Program/{ProgramCode}/{id_user}/{id_client}")]
public object GetProgramSettingsFromFile(string ProgramCode, string id_user, int id_client)
{
//AnalyticsUser newEntry = new AnalyticsUser
//{
// id_user = id_user,
// ProgramCode = ProgramCode,
// DateTime = DateTime.Now,
// id_client = id_client
//};
//db.AnalyticsUsers.Add(newEntry);
//db.SaveChanges();
string secondPart = "api/program/" + ProgramCode + ".json";
var allText = (new WebClient()).DownloadString(uriPath + secondPart);
object jsonObject = JsonConvert.DeserializeObject(allText);
return jsonObject;
}
it works fine on localhost and on published. So what is going in here? I can't seem to replicate the error locally since it all works fine. Is there any idea?
alright it was something in the Azure SQL server that was producing the error. For other that might encounter the same problem, cause localhost connecting to the database was working fine, also using the webconfig connection string, means that something is blocking it when published.
In Azure SQL Database Firewall settings there is a switch:
Allow Azure services and resources to access this server
This one had to be to yes (was on No)
Now it's working fine (the SAVE analytics setting is an internal connection) that is why ta was working without fine but with it got blocked.
Because you can run normally locally, you can debug or find the ConnectionString in the project (appconfig.json or web.config file).
Check your ConnectionString and replace the SQL Server connection string in the production environment.
You can configure the strings of the production environment in the configuration file or on the portal.
Tips:
If you don't have azure sql server, as long as the sql server that can be accessed on the public network is also possible.
Note that the table structure and stored procedures or functions of the database in the production environment must be consistent.
Related
I've been using GCP SecretManager in .Net core project ,while accessing one of the secret placed in GCP it throws an error
Grpc.Core.RpcException: 'Status(StatusCode="Unavailable",
Detail="failed to connect to all addresses",
DebugException="Grpc.Core.Internal.CoreErrorDetailException:
{"created":"#1621849302.013000000","description":"Failed to pick
subchannel","file":"......\src\core\ext\filters\client_channel\client_channel.cc","file_line":5397,"referenced_errors":[{"created":"#1621849296.458000000","description":"failed
to connect to all
addresses","file":"......\src\core\ext\filters\client_channel\lb_policy\pick_first\pick_first.cc","file_line":398,"grpc_status":14}]}")'
public String AccessSecretVersion(string projectId = "strategic-ivy-310114", string secretId = "connectionString", string secretVersionId = "1")
{
var credential = GoogleCredential.FromFile(#"C:\Learning\SampleApps\CosmosWithSecret\CosmosDBApp\CosmosDb_Demo_Crud\strategic-ivy-615459-a0f786577j32.json");
// Create the client.
SecretManagerServiceClient client = SecretManagerServiceClient.Create();
// Build the resource name.
SecretVersionName secretVersionName = new SecretVersionName(projectId, secretId, secretVersionId);
// Call the API.
AccessSecretVersionResponse result = client.AccessSecretVersion(secretVersionName);
// Convert the payload to a string. Payloads are bytes by default.
String payload = result.Payload.Data.ToStringUtf8();
return payload;
}
I've also got this error.
I'm running the application on Windows, and what actually worked for me was to run it from WSL. For some reason it crashes on Windows.
I tried this link in stackoverflow but not getting the client's name.
clientHostName = clientIpAddress = string.Empty;
try
{
clientIpAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (string.IsNullOrEmpty(clientIpAddress))
{
clientIpAddress = Request.ServerVariables["REMOTE_ADDR"];
}
System.Net.IPAddress myIP = System.Net.IPAddress.Parse(clientIpAddress);
System.Net.IPHostEntry GetIPHost = System.Net.Dns.GetHostEntry(myIP);
clientHostName = GetIPHost.HostName; // Working in dev environment. Moving to QA env this is returning null
}
catch { }
Take a look at blowdarts answer in the post you linked. It is not possible to get the machine name of remote machines this way. If you are in control of the client application you may try to make the client explicitly send it's machine name instead.
I'm trying to store a local SQLite database in the internal storage of the device. When I was using an emulator , this:
static string dbName = "totems.sqlite";
string dbPath = Path.Combine (Android.OS.Environment.ExternalStorageDirectory.ToString (), dbName);
worked fine. But when I tried to debug on my Nexus 5, it didn't work, because it doesn't have external storage. I searched where to store it so it could run on my Nexus as well. I replaced it with:
static string dbName = "totems.sqlite";
string dbPath = Path.Combine ("/data/data/com.companyname.totem/databases/", dbName);
But now it doesn't work on my Nexus 5 and it doesn't work on my emulator. It says it can't find the path.
What am I doing wrong?
Thanks in advance.
I know this is an old thread, but the old answer has a typo. The working syntax should be :
string path = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "DatabaseName.txt");
Im using the following code:
string path = Path.Combine(System.Enviroment.GetFolderPath(System.Enviroment.SpecialFolder.Personal), "data.txt");
I think that should write into the internal storage like you want
From docs.com
LocalApplicationData: The directory that serves as a common
repository for application-specific data that is used by the current,
non-roaming user.
Personal: The directory that serves as a common repository for
documents. This member is equivalent to MyDocuments.
From this I use:
var db_directory = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData),"databases"))
var db_path = Path.Combine(db_directory,"data.db");
Also from this sample (XF)
docs.com xamarin tutorial
public static Database Database
{
get
{
if (database == null)
{
database = new Database(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "people.db3"));
}
return database;
}
}
Here is my code to create an application
public static bool CreateApplication(String websiteName, String applicationName, String AppDIR,String appPoolName)
{
try
{
var windowsDir = Environment.GetEnvironmentVariable("SystemRoot");
Process.Start(windowsDir+#"\system32\inetsrv\appcmd","unlock config -section:system.webServer/security/authentication/windowsAuthentication");
Process.Start(windowsDir+#"\system32\inetsrv\appcmd","unlock config -section:system.webServer/security/authentication/anonymousAuthentication");
ServerManager iisManager = new ServerManager();
if (!applicationName.Contains("/"))
applicationName = "/" + applicationName;
var app = iisManager.Sites[websiteName].Applications.Add(applicationName, AppDIR);
app.ApplicationPoolName = appPoolName;
var config = app.GetWebConfiguration();
var anonsection = config.GetSection("system.webServer/security/authentication/anonymousAuthentication", iisManager.Sites[websiteName].Name + applicationName);
anonsection["enabled"] = false;
var winsection = config.GetSection("system.webServer/security/authentication/windowsAuthentication", iisManager.Sites[websiteName].Name + applicationName);
winsection["enabled"] = true;
iisManager.CommitChanges(); //Blows up here
return true;
}
catch
{
return false;
}
}
Everything is fine until it hit's the commit changes method call.
It throws this error
Error: Cannot write configuration file
All of the code is verified as working except for where I change the enabled values to false and true.
When I added these in it started to explode.
Is there any way to fix this from code, that can be distributed to other machines?
Update:
After re-locking the files
like this
Process.Start(windowsDir + #"\system32\inetsrv\appcmd", "lock config -section:system.webServer/security/authentication/windowsAuthentication");
Process.Start(windowsDir + #"\system32\inetsrv\appcmd", "lock config -section:system.webServer/security/authentication/anonymousAuthentication");
I now get this error
Error: Cannot commit configuration changes because the file has
changed on disk
I also ran into the second of your two issues (Error: Cannot commit configuration changes because the file has changed on disk) for our c# application which we use to configure IIS servers as part of our deploy operation.
For me in the end it was unintentionally nesting two using statements wrapped around the ServerManager object that caused the problem.
For your particular situation I would try to add a using statement for your reference to ServerManager and ensure that the command line appcmd calls are outside the using statement or moved within the using statement but translated into API calls via the ServerManager object.
I need to create a Console application that can copy a table from one remote sql server instance to another remote sql server instance.
I'm using a library called EzAPI
Both connections (Source and Destinations) and table name will be provided as parameters to the Console application.
Here is my try:
public class OleDBToOleDB : EzSrcDestPackage<EzOleDbSource, EzSqlOleDbCM, EzOleDbDestination, EzSqlOleDbCM>
{
public OleDBToOleDB(Package p) : base(p) { }
public static implicit operator OleDBToOleDB(Package p) { return new OleDBToOleDB(p); }
public OleDBToOleDB(string SrcServer, string SrcDB, string SrcTable,string SrcUser,string SrcPassword, string DstServer, string DstDB, string DstTable,string DstUser,string DstPassword)
{
SrcConn.SetConnectionString(SrcServer, SrcDB);
SrcConn.ServerName = SrcServer;
SrcConn.InitialCatalog = SrcDB;
SrcConn.UserName = SrcUser;
SrcConn.Password = SrcPassword;
Source.Table = SrcTable;
DestConn.SetConnectionString(DstServer, DstDB);
DestConn.ServerName = DstServer;
DestConn.InitialCatalog = DstDB;
DestConn.UserName = DstUser;
DestConn.Password = DstPassword;
Dest.Table = DstTable;
}
}
static void Main(string[] args)
{
OleDBToOleDB p = new OleDBToOleDB("localhost", "TestDB", "Address", "sa", "123", "localhost", "DestDB", "Address", "sa", "123");
p.Execute();
Console.Write(string.Format("Package2 executed with result {0}\n",p.ExecutionResult));
}
The problem with this code is:
It does not create the table on the destination server, so I should
create it manually by myself.
This code runs successfully on the localhost, but when I try to
change the server name to a remote server it raises this error:
Unhandled Exception: System.Runtime.InteropServices.COMException
(0xC020801C): Exception from HRESULT: 0xC020801C
After searching on the web I found that this error means that this error is an Integration services AcquireConnections exception.
So how can I get this code running on a remote sql server instance and have the package create the table on the destination server before transferring the data.
Thank you in advance.
SSIS needs both tabled during the package generation, since it has to get the whole metadata for each column in your tables. You can set the ValidateMetadata property to false, in this case it will not validate it, but you will need to fill all the data by yourself. This is not easy.
I think the most easy thing you can do is:
1)generate the package with local connections and turn off the validation for your destination component
2)now set the new connection strings to your source and destination compoennts
3)run the package
this is a not really clean workaround. This should be usually done with a configurations, but since you do not save your package you can try this as well.
I think it can be also easier to implement your task with SqlBuldCopy without SSIS