{"id":82,"date":"2020-12-18T16:09:45","date_gmt":"2020-12-18T15:09:45","guid":{"rendered":"https:\/\/www.meb.ki.se\/sites\/meb-it\/?p=82"},"modified":"2025-10-21T11:46:20","modified_gmt":"2025-10-21T09:46:20","slug":"how-to-access-the-registry-server-kosmos","status":"publish","type":"post","link":"https:\/\/www.meb.ki.se\/sites\/meb-it\/how-to-access-the-registry-server-kosmos\/","title":{"rendered":"How to access the registry server kosmos"},"content":{"rendered":"\n<p>You will be told the database and schema names by the DBA, when you are given access.<\/p>\n\n\n\n<p>You will be using your MEB account as authorization to access the data, i.e. you will use the same username and password that you use to log into your computer or VDI account.<\/p>\n\n\n\n<p>If you are running from a Windows machine, the operating system will already have your credentials, and will use those <em>on your behalf<\/em>. <\/p>\n\n\n\n<p>If you are on a Mac of Linux machine (including matrix and vector), you may have to set up a Kerberos ticket.  Do this with <em><code>kinit<\/code><\/em>, and use the same password you use when logging into the MEB computers (your &#8220;Windows password&#8221;):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">[joelus@matrix ~]$ kinit\nPassword for joelus@MEB.KI.SE:\n[joelus@matrix ~]$<\/code><\/pre>\n\n\n\n<p>If you are using <a href=\"http:\/\/tensor.github.io\" data-type=\"link\" data-id=\"tensor.github.io\">tensor<\/a>, then this process has been abstracted away into a <em>module<\/em>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">[joelus@tensor ~]$ ml mebauth<\/code><\/pre>\n\n\n\n<p>Note that when you have been granted a new access, you need to log out and log in again, to use the new access.<\/p>\n\n\n\n<p>Questions? Mail them to <a href=\"mailto:dba-support@meb.ki.se\" data-type=\"mailto\" data-id=\"mailto:dba-support@meb.ki.se\">dba-support@meb.ki.se<\/a>. If at all possible, include code and relevant log messages!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"SAS\">SAS<\/h2>\n\n\n\n<p>Using CRIME3 as an example dataset, the libname statement looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"sas\" class=\"language-sas\">libname CRIME3 odbc \n  noprompt=\"dsn=kosmos;database=MGRCRIME3\" \n  schema=\"MGRCRIME3\";<\/code><\/pre>\n\n\n\n<p>Note that this example also works unchanged on the compute server (<em>matrix<\/em>), and with <em>rsubmit<\/em>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"STATA\">STATA<\/h2>\n\n\n\n<p>Using CRIME3, and the view V_LMED2015 as an example, the load statement looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">odbc load, \n   table(\"MGRCRIME3.MGRCRIME3.V_LMED2015\") \n   noquote dsn(\"kosmos\");<\/code><\/pre>\n\n\n\n<p>i.e. you specify the three-level path &#8230; The <em>noquote<\/em> keyword is <strong>mandatory<\/strong>.<\/p>\n\n\n\n<p>To access the list of tables and view, use<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">odbc load, \n   table(\"MGRCRIME3.INFORMATION_SCHEMA.TABLES\") \n   noquote dsn(\"kosmos\");<\/code><\/pre>\n\n\n\n<p>Note that these examples works also on the compute server (<em>matrix<\/em>), unchanged.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"R\">R<\/h2>\n\n\n\n<p>Using CRIME3 and the V_LMED2015 view as an example, a simple version of R code, using only basic packages, looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"r\" class=\"language-r\"># install the DBI and odbc packages (this is a one-time install)\ninstall.packages(c(\"DBI\", \"odbc\"))\n\n# load the DBI package (once per session) \nlibrary(\"DBI\")\n# and possibly also the odbc package ...\n# library(\"odbc\") \n\n# connect to the database\ndbhandle &lt;- dbConnect(odbc::odbc(), \"kosmos\")\n# make a query\nquery &lt;- dbSendQuery(dbhandle, 'select ATC, LAKMED from MGRCRIME3.MGRCRIME3.V_LMED2015 where TKOST &gt; 500000')\n\n# get data\nresult &lt;- dbFetch(query)<\/code><\/pre>\n\n\n\n<p>i.e. you specify the three-level path &#8230; but see below for another way of doing this.<\/p>\n\n\n\n<p>To access the list of tables and view, use<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"r\" class=\"language-r\"># setup as above\ncolumn_query &lt;- dbSendQuery(dbhandle, \n   'select * from MGRCRIME3.INFORMATION_SCHEMA.TABLES')\nprint(dbFetch(column_query))<\/code><\/pre>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/db.rstudio.com\/r-packages\/dplyr\/\" target=\"_blank\">dplyr<\/a> also has support for querying the database:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"r\" class=\"language-r\"># install DBI, odbc as above\n# install dplyr, dbplyr\ninstall.packages(c(\"dplyr\", \"dbplyr\"))\n\nlibrary(dplyr)\nlibrary(dbplyr)    ## for in_schema\ncrime3 &lt;- DBI::dbConnect(odbc::odbc(),\n   dsn = \"kosmos\", database = \"MGRCRIME3\")\nlmed15 &lt;- tbl(crime3, in_schema(\"MGRCRIME3\", \"V_LMED2015\"))\nexpensive &lt;- lmed15 %&gt;% \n   filter(tkost &gt; 500000) %&gt;% \n   select(ATC, LAKMED)<\/code><\/pre>\n\n\n\n<p>Note that these examples works also on the compute server (<em>vector<\/em>), unchanged.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Python<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"python\" class=\"language-python\">import pandas as pd\nimport pyodbc \n  \nconn = pyodbc.connect('DSN=kosmos;'\n                      'Database=MGRCRIME3;')\ndf = pd.read_sql_query('select distinct ATC, LAKMED from MGRCRIME3.V_LMED2015 where TKOST &gt; 500000', conn)\n\nprint(df)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">VS Code<\/h2>\n\n\n\n<p>You will need the <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ms-mssql.mssql\">SQL Server (mssql) extension<\/a>. You will get a new icon to the left, looking like a server (<img loading=\"lazy\" decoding=\"async\" width=\"46\" height=\"44\" class=\"wp-image-1022\" style=\"width: 23px\" src=\"https:\/\/www.meb.ki.se\/sites\/meb-it\/wp-content\/uploads\/sites\/12\/2020\/12\/sqlserver-icon-vscode.png\" alt=\"\">). If you click that you will see your connections &#8212; with the option to add a connection. Or type&nbsp;<strong>F1<\/strong>, then select the&nbsp;<strong>MS SQL: Connect<\/strong>&nbsp;command to open the connection workflow. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"695\" height=\"602\" src=\"https:\/\/www.meb.ki.se\/sites\/meb-it\/wp-content\/uploads\/sites\/12\/2020\/12\/connection_dialog.png\" alt=\"\" class=\"wp-image-1023\" srcset=\"https:\/\/www.meb.ki.se\/sites\/meb-it\/wp-content\/uploads\/sites\/12\/2020\/12\/connection_dialog.png 695w, https:\/\/www.meb.ki.se\/sites\/meb-it\/wp-content\/uploads\/sites\/12\/2020\/12\/connection_dialog-300x260.png 300w\" sizes=\"auto, (max-width: 695px) 100vw, 695px\" \/><\/figure>\n\n\n\n<p>Server name should be <strong>kosmos<\/strong>, and you should use Windows Authentication. Check the &#8220;Trust server certificate&#8221; box.  The database name is optional.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You will be told the database and schema names by the DBA, when you are given access. You will be using your MEB account as authorization to access the data, i.e. you will use the same username and password that you use to log into your computer or VDI account. If you are running from [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[11,6,30,21,34,35],"tags":[],"class_list":["post-82","post","type-post","status-publish","format-standard","hentry","category-dba","category-faq","category-python","category-r","category-sas","category-stata"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":6}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.meb.ki.se\/sites\/meb-it\/wp-json\/wp\/v2\/posts\/82","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.meb.ki.se\/sites\/meb-it\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.meb.ki.se\/sites\/meb-it\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.meb.ki.se\/sites\/meb-it\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.meb.ki.se\/sites\/meb-it\/wp-json\/wp\/v2\/comments?post=82"}],"version-history":[{"count":33,"href":"https:\/\/www.meb.ki.se\/sites\/meb-it\/wp-json\/wp\/v2\/posts\/82\/revisions"}],"predecessor-version":[{"id":1029,"href":"https:\/\/www.meb.ki.se\/sites\/meb-it\/wp-json\/wp\/v2\/posts\/82\/revisions\/1029"}],"wp:attachment":[{"href":"https:\/\/www.meb.ki.se\/sites\/meb-it\/wp-json\/wp\/v2\/media?parent=82"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.meb.ki.se\/sites\/meb-it\/wp-json\/wp\/v2\/categories?post=82"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.meb.ki.se\/sites\/meb-it\/wp-json\/wp\/v2\/tags?post=82"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}