using System;
namespace Falcon.Core.Helpers
{
public class GeoCalculator
{
private static double ToRadians(double degree)
{
return (degree * Math.PI) / 180;
}
public static double Distance(double latitude1, double latitude2, double longitude1, double longitude2)
{
// The math module contains
// a function named toRadians
// which converts from degrees
// to radians.
longitude1 = ToRadians(longitude1);
longitude2 = ToRadians(longitude2);
latitude1 = ToRadians(latitude1);
latitude2 = ToRadians(latitude2);
// Haversine formula
double diffLongitude = longitude2 - longitude1;
double diffLatitude = latitude2 - latitude1;
double a = Math.Pow(Math.Sin(diffLatitude / 2), 2) +
Math.Cos(latitude1) * Math.Cos(latitude2) *
Math.Pow(Math.Sin(diffLongitude / 2), 2);
double c = 2 * Math.Asin(Math.Sqrt(a));
// Radius of earth in
// kilometers. Use 3956
// for miles
double r = 6371;
// calculate the result
return (c * r);
}
}
}
31 Ağustos 2020 Pazartesi
Enlem boylam uzaklık hesaplama (c#)
Enlem boylam uzaklık hesaplama
Since you're using SQL Server 2008, you have the geography data type available, which is designed for exactly this kind of data:
DECLARE @source geography = 'POINT(0 51.5)'
DECLARE @target geography = 'POINT(-3 56)'
SELECT @source.STDistance(@target)
Gives
----------------------
538404.100197555
(1 row(s) affected)
Telling us it is about 538 km from (near) London to (near) Edinburgh.
Naturally there will be an amount of learning to do first, but once you know it it's far far easier than implementing your own Haversine calculation; plus you get a LOT of functionality.
If you want to retain your existing data structure, you can still use STDistance, by constructing suitable geography instances using the Point method:
DECLARE @orig_lat DECIMAL(12, 9)
DECLARE @orig_lng DECIMAL(12, 9)
SET @orig_lat=53.381538 set @orig_lng=-1.463526
DECLARE @orig geography = geography::Point(@orig_lat, @orig_lng, 4326);
SELECT *,
@orig.STDistance(geography::Point(dest.Latitude, dest.Longitude, 4326))
AS distance
--INTO #includeDistances
FROM #orig dest
14 Mayıs 2020 Perşembe
Veritabanı ortamları oluşturma
DECLARE @environments TABLE (Environment VARCHAR(255) not null);
INSERT @environments(Environment) VALUES ('Test'),('Dev'),('DevAkif'),('DevGuest');
DECLARE @environment VARCHAR(255);
DECLARE @prefix VARCHAR(255)='DB_Name_';
DECLARE @path VARCHAR(255) =N'C:\MSSQL\Backup\Yesterday\Backup.bak';
DECLARE @backup_dbname VARCHAR(255) = 'DB_Name';
DECLARE @backup_dbname_log VARCHAR(255) = 'DB_Name_log';
DECLARE @data_path VARCHAR(255) ='C:\MSSQL\DATA\';
DECLARE @mdf VARCHAR(4)= '.mdf';
DECLARE @log VARCHAR(4)='_log';
DECLARE @ldf VARCHAR(4)= '.ldf';
DECLARE CreateEnvironmentsCursor CURSOR FOR
SELECT Environment FROM @environments;
OPEN CreateEnvironmentsCursor
FETCH NEXT FROM CreateEnvironmentsCursor INTO @environment ;
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @environment+ ' yedek alınıyor...';
DECLARE @environment_db_name VARCHAR(255) =@prefix+@environment;
DECLARE @environment_logical_name VARCHAR(255) = @environment_db_name;
DECLARE @environment_mdf_path VARCHAR(255) = @data_path +@environment_db_name+ @mdf;
DECLARE @environment_logical_log_name VARCHAR(255) = @environment_db_name + @log;
DECLARE @environment_ldf_path VARCHAR(255) = @data_path +@environment_db_name+@log+@ldf;
IF EXISTS (SELECT name FROM sys.databases WHERE name = @environment_db_name)
BEGIN
EXEC msdb.dbo.sp_delete_database_backuphistory @database_name = @environment_db_name
USE [master]
EXEC('DROP DATABASE '+@environment_db_name)
END
RESTORE FILELISTONLY FROM DISK=@path
RESTORE DATABASE @environment_db_name
FROM DISK = @path
WITH
MOVE @backup_dbname TO @environment_mdf_path,
MOVE @backup_dbname_log TO @environment_ldf_path
EXEC('ALTER DATABASE '+@environment_db_name+' MODIFY FILE (NAME=['+@backup_dbname+'], NEWNAME='+@environment_logical_name+')');
EXEC('ALTER DATABASE '+@environment_db_name+' MODIFY FILE (NAME=['+@backup_dbname_log+'], NEWNAME='+@environment_logical_log_name+')');
EXEC('USE '+@environment_db_name +'; '
+' ALTER DATABASE '+@environment_logical_name+' SET RECOVERY SIMPLE WITH NO_WAIT;'
+'DBCC SHRINKFILE('+@environment_logical_log_name+') ;'
+'ALTER DATABASE '+@environment_logical_name+' SET RECOVERY FULL WITH NO_WAIT;');
IF USER_ID(@environment_db_name) IS NULL
BEGIN
CREATE USER [TestUser] FOR LOGIN [TestUser] -- Önceden oluşturulan user
END
ALTER ROLE [db_owner] ADD MEMBER [TestUser]
FETCH NEXT FROM CreateEnvironmentsCursor INTO @environment
END
CLOSE CreateEnvironmentsCursor
DEALLOCATE CreateEnvironmentsCursor
INSERT @environments(Environment) VALUES ('Test'),('Dev'),('DevAkif'),('DevGuest');
DECLARE @environment VARCHAR(255);
DECLARE @prefix VARCHAR(255)='DB_Name_';
DECLARE @path VARCHAR(255) =N'C:\MSSQL\Backup\Yesterday\Backup.bak';
DECLARE @backup_dbname VARCHAR(255) = 'DB_Name';
DECLARE @backup_dbname_log VARCHAR(255) = 'DB_Name_log';
DECLARE @data_path VARCHAR(255) ='C:\MSSQL\DATA\';
DECLARE @mdf VARCHAR(4)= '.mdf';
DECLARE @log VARCHAR(4)='_log';
DECLARE @ldf VARCHAR(4)= '.ldf';
DECLARE CreateEnvironmentsCursor CURSOR FOR
SELECT Environment FROM @environments;
OPEN CreateEnvironmentsCursor
FETCH NEXT FROM CreateEnvironmentsCursor INTO @environment ;
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @environment+ ' yedek alınıyor...';
DECLARE @environment_db_name VARCHAR(255) =@prefix+@environment;
DECLARE @environment_logical_name VARCHAR(255) = @environment_db_name;
DECLARE @environment_mdf_path VARCHAR(255) = @data_path +@environment_db_name+ @mdf;
DECLARE @environment_logical_log_name VARCHAR(255) = @environment_db_name + @log;
DECLARE @environment_ldf_path VARCHAR(255) = @data_path +@environment_db_name+@log+@ldf;
IF EXISTS (SELECT name FROM sys.databases WHERE name = @environment_db_name)
BEGIN
EXEC msdb.dbo.sp_delete_database_backuphistory @database_name = @environment_db_name
USE [master]
EXEC('DROP DATABASE '+@environment_db_name)
END
RESTORE FILELISTONLY FROM DISK=@path
RESTORE DATABASE @environment_db_name
FROM DISK = @path
WITH
MOVE @backup_dbname TO @environment_mdf_path,
MOVE @backup_dbname_log TO @environment_ldf_path
EXEC('ALTER DATABASE '+@environment_db_name+' MODIFY FILE (NAME=['+@backup_dbname+'], NEWNAME='+@environment_logical_name+')');
EXEC('ALTER DATABASE '+@environment_db_name+' MODIFY FILE (NAME=['+@backup_dbname_log+'], NEWNAME='+@environment_logical_log_name+')');
EXEC('USE '+@environment_db_name +'; '
+' ALTER DATABASE '+@environment_logical_name+' SET RECOVERY SIMPLE WITH NO_WAIT;'
+'DBCC SHRINKFILE('+@environment_logical_log_name+') ;'
+'ALTER DATABASE '+@environment_logical_name+' SET RECOVERY FULL WITH NO_WAIT;');
IF USER_ID(@environment_db_name) IS NULL
BEGIN
CREATE USER [TestUser] FOR LOGIN [TestUser] -- Önceden oluşturulan user
END
ALTER ROLE [db_owner] ADD MEMBER [TestUser]
FETCH NEXT FROM CreateEnvironmentsCursor INTO @environment
END
CLOSE CreateEnvironmentsCursor
DEALLOCATE CreateEnvironmentsCursor
13 Mayıs 2020 Çarşamba
SINGLE USER modundan veritabanını MULTI USER olarak ayarlama
use master
GO
select
d.name,
d.dbid,
spid,
login_time,
nt_domain,
nt_username,
loginame
from sysprocesses p
inner join sysdatabases d
on p.dbid = d.dbid
where d.name = 'dbname'
GO
kill 56 --=> kill the number in spid field
GO
exec sp_dboption 'dbname', 'single user', 'FALSE'
GO
https://stackoverflow.com/questions/14652923/set-database-from-single-user-mode-to-multi-user
Is there any way to get a list of open/allocated cursors in SQL server?
USE MASTER
GO
select s.session_id, s.host_name, s.program_name, s.client_interface_name, s.login_name
, c.cursor_id, c.properties, c.creation_time, c.is_open, con.text,
l.resource_type, d.name, l.request_type, l.request_Status, l.request_reference_count, l.request_lifetime, l.request_owner_type
from sys.dm_exec_cursors(0) c
left outer join (select * from sys.dm_exec_connections c cross apply sys.dm_exec_sql_text(c.most_recent_sql_handle) mr) con on c.session_id = con.session_id
left outer join sys.dm_exec_sessions s on s.session_id = c.session_id
left outer join sys.dm_tran_locks l on l.request_session_id = c.session_id
left outer join sys.databases d on d.database_id = l.resource_database_id
Açık kalan Cursorları listeleme
Kaynak: https://stackoverflow.com/questions/265605/is-there-any-way-to-get-a-list-of-open-allocated-cursors-in-sql-server
GO
select s.session_id, s.host_name, s.program_name, s.client_interface_name, s.login_name
, c.cursor_id, c.properties, c.creation_time, c.is_open, con.text,
l.resource_type, d.name, l.request_type, l.request_Status, l.request_reference_count, l.request_lifetime, l.request_owner_type
from sys.dm_exec_cursors(0) c
left outer join (select * from sys.dm_exec_connections c cross apply sys.dm_exec_sql_text(c.most_recent_sql_handle) mr) con on c.session_id = con.session_id
left outer join sys.dm_exec_sessions s on s.session_id = c.session_id
left outer join sys.dm_tran_locks l on l.request_session_id = c.session_id
left outer join sys.databases d on d.database_id = l.resource_database_id
Açık kalan Cursorları listeleme
Kaynak: https://stackoverflow.com/questions/265605/is-there-any-way-to-get-a-list-of-open-allocated-cursors-in-sql-server
6 Kasım 2019 Çarşamba
why we use moduleId:module.id in angular2
relative assets for components, like templateUrl and styleUrls in the @Component decorator.
moduleId is used to resolve relative paths for your stylesheets and templates as it says in the documentation.
Without Module ID
moduleId is used to resolve relative paths for your stylesheets and templates as it says in the documentation.
Without Module ID
@Component({
selector: 'my-component',
templateUrl: 'app/components/my.component.html',
styleUrls: ['app/components/my.component.css']
})
With Module ID@Component({
moduleId: module.id,
selector: 'my-component',
templateUrl: 'my.component.html',
styleUrls: ['my.component.css']
})
21 Mart 2019 Perşembe
Json Data verilen navigasyon içeriğini getirme
getDataByNav(dataNav: string, response: any) {
const navs = dataNav.split('.');
let lastObj = Object.assign([], response);
if (navs && navs.length > 0) {
for (let i = 0; i < navs.length; i++) {
lastObj = lastObj[navs[i].toString()]
}
}
return lastObj;
}
Kaydol:
Kayıtlar (Atom)
.net 6 mapget kullanımı
app.UseEndpoints(endpoints => { endpoints.MapGet("/", async context => { var response = JsonConvert.Seriali...
-
XAMPP Apache MySQL PHP 5 PHP 4 1.8.3 2.4.9 5.6.16 5.5.11 1.8.2 2.4.9 5.5.36 5.4.27 1.8.1 2.4.3 5.5.27 5.4.7 1...
-
var mystring = "this,is,a,test" mystring . replace ( /,/ g , "newchar" ); DEMO: http://jsfiddle.net/d4N9s/
-
SELECT * INTO [new_BK] FROM [old_table]