We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Creation of db files when import qcodes
It's not a bug I guess, but I think its still unwanted. 

### Steps to reproduce
Set any directory to the current working directory
Execute a python script/program that just imports the qcodes module

### Expected behaviour
No side-effects of the file system

### Actual behaviour
An experiment.db file is created in the current working directory. 

I think it's better if measurement databases are only created when we actually call a function that initialized an experiment. 
I use the qcodes module to load my experimental data from a lot of different working directories, like folders where I work on papers, during the analyses, etc... 

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `qcodes/dataset/database.py`
Content:
```
1 # high-level interface to the database
2 
3 from qcodes.dataset.sqlite_base import connect as _connect
4 from qcodes.dataset.sqlite_base import init_db as _init_db
5 import qcodes.config
6 
7 
8 def get_DB_location() -> str:
9     return qcodes.config["core"]["db_location"]
10 
11 
12 def get_DB_debug() -> bool:
13     return bool(qcodes.config["core"]["db_debug"])
14 
15 
16 def initialise_database() -> None:
17     """
18     Initialise a database in the location specified by the config object
19     If the database already exists, nothing happens
20 
21     Args:
22         config: An instance of the config object
23     """
24     conn = _connect(get_DB_location(), get_DB_debug())
25     # init is actually idempotent so it's safe to always call!
26     _init_db(conn)
27     conn.close()
28     del conn
29
```

Path: `qcodes/__init__.py`
Content:
```
1 """Set up the main qcodes namespace."""
2 
3 # flake8: noqa (we don't need the "<...> imported but unused" error)
4 
5 # config
6 
7 from qcodes.config import Config
8 from qcodes.utils.helpers import add_to_spyder_UMR_excludelist
9 
10 # we dont want spyder to reload qcodes as this will overwrite the default station
11 # instrument list and running monitor
12 add_to_spyder_UMR_excludelist('qcodes')
13 config = Config() # type: Config
14 
15 from qcodes.version import __version__
16 
17 plotlib = config.gui.plotlib
18 if plotlib in {'QT', 'all'}:
19     try:
20         from qcodes.plots.pyqtgraph import QtPlot
21     except Exception:
22         print('pyqtgraph plotting not supported, '
23               'try "from qcodes.plots.pyqtgraph import QtPlot" '
24               'to see the full error')
25 
26 if plotlib in {'matplotlib', 'all'}:
27     try:
28         from qcodes.plots.qcmatplotlib import MatPlot
29     except Exception:
30         print('matplotlib plotting not supported, '
31               'try "from qcodes.plots.qcmatplotlib import MatPlot" '
32               'to see the full error')
33 
34 
35 from qcodes.station import Station
36 from qcodes.loops import Loop, active_loop, active_data_set
37 from qcodes.measure import Measure
38 from qcodes.actions import Task, Wait, BreakIf
39 haswebsockets = True
40 try:
41     import websockets
42 except ImportError:
43     haswebsockets = False
44 if haswebsockets:
45     from qcodes.monitor.monitor import Monitor
46 
47 from qcodes.data.data_set import DataSet, new_data, load_data
48 from qcodes.data.location import FormatLocation
49 from qcodes.data.data_array import DataArray
50 from qcodes.data.format import Formatter
51 from qcodes.data.gnuplot_format import GNUPlotFormat
52 from qcodes.data.hdf5_format import HDF5Format
53 from qcodes.data.io import DiskIO
54 
55 from qcodes.instrument.base import Instrument
56 from qcodes.instrument.ip import IPInstrument
57 from qcodes.instrument.visa import VisaInstrument
58 from qcodes.instrument.channel import InstrumentChannel, ChannelList
59 
60 from qcodes.instrument.function import Function
61 from qcodes.instrument.parameter import (
62     Parameter,
63     ArrayParameter,
64     MultiParameter,
65     StandardParameter,
66     ManualParameter,
67     combine,
68     CombinedParameter)
69 from qcodes.instrument.sweep_values import SweepFixedValues, SweepValues
70 
71 from qcodes.utils import validators
72 from qcodes.utils.zmq_helpers import Publisher
73 from qcodes.instrument_drivers.test import test_instruments, test_instrument
74 
75 from qcodes.dataset.data_set import new_data_set, load_by_counter, load_by_id
76 from qcodes.dataset.experiment_container import new_experiment, load_experiment, load_experiment_by_name, \
77     load_last_experiment, experiments
78 from qcodes.dataset.sqlite_settings import SQLiteSettings
79 from qcodes.dataset.param_spec import ParamSpec
80 # TODO: do we want this?
81 from qcodes.dataset.sqlite_base import connect as _connect
82 from qcodes.dataset.sqlite_base import init_db as _init_db
83 
84 _c = _connect(config["core"]["db_location"], config["core"]["db_debug"])
85 # init is actually idempotent so it's safe to always call!
86 _init_db(_c)
87 _c.close()
88 del _c
89 
90 try:
91     get_ipython() # type: ignore # Check if we are in iPython
92     from qcodes.utils.magic import register_magic_class
93     _register_magic = config.core.get('register_magic', False)
94     if _register_magic is not False:
95         register_magic_class(magic_commands=_register_magic)
96 except NameError:
97     pass
98 except RuntimeError as e:
99     print(e)
100 
101 # ensure to close all instruments when interpreter is closed
102 import atexit
103 atexit.register(Instrument.close_all)
104 
105 def test(**kwargs):
106     """
107     Run QCoDeS tests. This requires the test requirements given
108     in test_requirements.txt to be installed.
109     All arguments are forwarded to pytest.main
110     """
111     try:
112         import pytest
113     except ImportError:
114         print("Need pytest to run tests")
115         return
116     args = ['--pyargs', 'qcodes.tests']
117     retcode = pytest.main(args, **kwargs)
118     return retcode
119 
120 
121 test.__test__ = False # type: ignore # Don't try to run this method as a test
122
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/qcodes/__init__.py b/qcodes/__init__.py
--- a/qcodes/__init__.py
+++ b/qcodes/__init__.py
@@ -77,15 +77,6 @@
     load_last_experiment, experiments
 from qcodes.dataset.sqlite_settings import SQLiteSettings
 from qcodes.dataset.param_spec import ParamSpec
-# TODO: do we want this?
-from qcodes.dataset.sqlite_base import connect as _connect
-from qcodes.dataset.sqlite_base import init_db as _init_db
-
-_c = _connect(config["core"]["db_location"], config["core"]["db_debug"])
-# init is actually idempotent so it's safe to always call!
-_init_db(_c)
-_c.close()
-del _c
 
 try:
     get_ipython() # type: ignore # Check if we are in iPython
diff --git a/qcodes/dataset/database.py b/qcodes/dataset/database.py
--- a/qcodes/dataset/database.py
+++ b/qcodes/dataset/database.py
@@ -1,12 +1,14 @@
 # high-level interface to the database
 
+from os.path import expanduser
+
 from qcodes.dataset.sqlite_base import connect as _connect
 from qcodes.dataset.sqlite_base import init_db as _init_db
 import qcodes.config
 
 
 def get_DB_location() -> str:
-    return qcodes.config["core"]["db_location"]
+    return expanduser(qcodes.config["core"]["db_location"])
 
 
 def get_DB_debug() -> bool:

{"golden_diff": "diff --git a/qcodes/__init__.py b/qcodes/__init__.py\n--- a/qcodes/__init__.py\n+++ b/qcodes/__init__.py\n@@ -77,15 +77,6 @@\n     load_last_experiment, experiments\n from qcodes.dataset.sqlite_settings import SQLiteSettings\n from qcodes.dataset.param_spec import ParamSpec\n-# TODO: do we want this?\n-from qcodes.dataset.sqlite_base import connect as _connect\n-from qcodes.dataset.sqlite_base import init_db as _init_db\n-\n-_c = _connect(config[\"core\"][\"db_location\"], config[\"core\"][\"db_debug\"])\n-# init is actually idempotent so it's safe to always call!\n-_init_db(_c)\n-_c.close()\n-del _c\n \n try:\n     get_ipython() # type: ignore # Check if we are in iPython\ndiff --git a/qcodes/dataset/database.py b/qcodes/dataset/database.py\n--- a/qcodes/dataset/database.py\n+++ b/qcodes/dataset/database.py\n@@ -1,12 +1,14 @@\n # high-level interface to the database\n \n+from os.path import expanduser\n+\n from qcodes.dataset.sqlite_base import connect as _connect\n from qcodes.dataset.sqlite_base import init_db as _init_db\n import qcodes.config\n \n \n def get_DB_location() -> str:\n-    return qcodes.config[\"core\"][\"db_location\"]\n+    return expanduser(qcodes.config[\"core\"][\"db_location\"])\n \n \n def get_DB_debug() -> bool:\n", "issue": "Creation of db files when import qcodes\nIt's not a bug I guess, but I think its still unwanted. \r\n\r\n### Steps to reproduce\r\nSet any directory to the current working directory\r\nExecute a python script/program that just imports the qcodes module\r\n\r\n### Expected behaviour\r\nNo side-effects of the file system\r\n\r\n### Actual behaviour\r\nAn experiment.db file is created in the current working directory. \r\n\r\nI think it's better if measurement databases are only created when we actually call a function that initialized an experiment. \r\nI use the qcodes module to load my experimental data from a lot of different working directories, like folders where I work on papers, during the analyses, etc... \n", "before_files": [{"content": "# high-level interface to the database\n\nfrom qcodes.dataset.sqlite_base import connect as _connect\nfrom qcodes.dataset.sqlite_base import init_db as _init_db\nimport qcodes.config\n\n\ndef get_DB_location() -> str:\n    return qcodes.config[\"core\"][\"db_location\"]\n\n\ndef get_DB_debug() -> bool:\n    return bool(qcodes.config[\"core\"][\"db_debug\"])\n\n\ndef initialise_database() -> None:\n    \"\"\"\n    Initialise a database in the location specified by the config object\n    If the database already exists, nothing happens\n\n    Args:\n        config: An instance of the config object\n    \"\"\"\n    conn = _connect(get_DB_location(), get_DB_debug())\n    # init is actually idempotent so it's safe to always call!\n    _init_db(conn)\n    conn.close()\n    del conn\n", "path": "qcodes/dataset/database.py"}, {"content": "\"\"\"Set up the main qcodes namespace.\"\"\"\n\n# flake8: noqa (we don't need the \"<...> imported but unused\" error)\n\n# config\n\nfrom qcodes.config import Config\nfrom qcodes.utils.helpers import add_to_spyder_UMR_excludelist\n\n# we dont want spyder to reload qcodes as this will overwrite the default station\n# instrument list and running monitor\nadd_to_spyder_UMR_excludelist('qcodes')\nconfig = Config() # type: Config\n\nfrom qcodes.version import __version__\n\nplotlib = config.gui.plotlib\nif plotlib in {'QT', 'all'}:\n    try:\n        from qcodes.plots.pyqtgraph import QtPlot\n    except Exception:\n        print('pyqtgraph plotting not supported, '\n              'try \"from qcodes.plots.pyqtgraph import QtPlot\" '\n              'to see the full error')\n\nif plotlib in {'matplotlib', 'all'}:\n    try:\n        from qcodes.plots.qcmatplotlib import MatPlot\n    except Exception:\n        print('matplotlib plotting not supported, '\n              'try \"from qcodes.plots.qcmatplotlib import MatPlot\" '\n              'to see the full error')\n\n\nfrom qcodes.station import Station\nfrom qcodes.loops import Loop, active_loop, active_data_set\nfrom qcodes.measure import Measure\nfrom qcodes.actions import Task, Wait, BreakIf\nhaswebsockets = True\ntry:\n    import websockets\nexcept ImportError:\n    haswebsockets = False\nif haswebsockets:\n    from qcodes.monitor.monitor import Monitor\n\nfrom qcodes.data.data_set import DataSet, new_data, load_data\nfrom qcodes.data.location import FormatLocation\nfrom qcodes.data.data_array import DataArray\nfrom qcodes.data.format import Formatter\nfrom qcodes.data.gnuplot_format import GNUPlotFormat\nfrom qcodes.data.hdf5_format import HDF5Format\nfrom qcodes.data.io import DiskIO\n\nfrom qcodes.instrument.base import Instrument\nfrom qcodes.instrument.ip import IPInstrument\nfrom qcodes.instrument.visa import VisaInstrument\nfrom qcodes.instrument.channel import InstrumentChannel, ChannelList\n\nfrom qcodes.instrument.function import Function\nfrom qcodes.instrument.parameter import (\n    Parameter,\n    ArrayParameter,\n    MultiParameter,\n    StandardParameter,\n    ManualParameter,\n    combine,\n    CombinedParameter)\nfrom qcodes.instrument.sweep_values import SweepFixedValues, SweepValues\n\nfrom qcodes.utils import validators\nfrom qcodes.utils.zmq_helpers import Publisher\nfrom qcodes.instrument_drivers.test import test_instruments, test_instrument\n\nfrom qcodes.dataset.data_set import new_data_set, load_by_counter, load_by_id\nfrom qcodes.dataset.experiment_container import new_experiment, load_experiment, load_experiment_by_name, \\\n    load_last_experiment, experiments\nfrom qcodes.dataset.sqlite_settings import SQLiteSettings\nfrom qcodes.dataset.param_spec import ParamSpec\n# TODO: do we want this?\nfrom qcodes.dataset.sqlite_base import connect as _connect\nfrom qcodes.dataset.sqlite_base import init_db as _init_db\n\n_c = _connect(config[\"core\"][\"db_location\"], config[\"core\"][\"db_debug\"])\n# init is actually idempotent so it's safe to always call!\n_init_db(_c)\n_c.close()\ndel _c\n\ntry:\n    get_ipython() # type: ignore # Check if we are in iPython\n    from qcodes.utils.magic import register_magic_class\n    _register_magic = config.core.get('register_magic', False)\n    if _register_magic is not False:\n        register_magic_class(magic_commands=_register_magic)\nexcept NameError:\n    pass\nexcept RuntimeError as e:\n    print(e)\n\n# ensure to close all instruments when interpreter is closed\nimport atexit\natexit.register(Instrument.close_all)\n\ndef test(**kwargs):\n    \"\"\"\n    Run QCoDeS tests. This requires the test requirements given\n    in test_requirements.txt to be installed.\n    All arguments are forwarded to pytest.main\n    \"\"\"\n    try:\n        import pytest\n    except ImportError:\n        print(\"Need pytest to run tests\")\n        return\n    args = ['--pyargs', 'qcodes.tests']\n    retcode = pytest.main(args, **kwargs)\n    return retcode\n\n\ntest.__test__ = False # type: ignore # Don't try to run this method as a test\n", "path": "qcodes/__init__.py"}], "after_files": [{"content": "# high-level interface to the database\n\nfrom os.path import expanduser\n\nfrom qcodes.dataset.sqlite_base import connect as _connect\nfrom qcodes.dataset.sqlite_base import init_db as _init_db\nimport qcodes.config\n\n\ndef get_DB_location() -> str:\n    return expanduser(qcodes.config[\"core\"][\"db_location\"])\n\n\ndef get_DB_debug() -> bool:\n    return bool(qcodes.config[\"core\"][\"db_debug\"])\n\n\ndef initialise_database() -> None:\n    \"\"\"\n    Initialise a database in the location specified by the config object\n    If the database already exists, nothing happens\n\n    Args:\n        config: An instance of the config object\n    \"\"\"\n    conn = _connect(get_DB_location(), get_DB_debug())\n    # init is actually idempotent so it's safe to always call!\n    _init_db(conn)\n    conn.close()\n    del conn\n", "path": "qcodes/dataset/database.py"}, {"content": "\"\"\"Set up the main qcodes namespace.\"\"\"\n\n# flake8: noqa (we don't need the \"<...> imported but unused\" error)\n\n# config\n\nfrom qcodes.config import Config\nfrom qcodes.utils.helpers import add_to_spyder_UMR_excludelist\n\n# we dont want spyder to reload qcodes as this will overwrite the default station\n# instrument list and running monitor\nadd_to_spyder_UMR_excludelist('qcodes')\nconfig = Config() # type: Config\n\nfrom qcodes.version import __version__\n\nplotlib = config.gui.plotlib\nif plotlib in {'QT', 'all'}:\n    try:\n        from qcodes.plots.pyqtgraph import QtPlot\n    except Exception:\n        print('pyqtgraph plotting not supported, '\n              'try \"from qcodes.plots.pyqtgraph import QtPlot\" '\n              'to see the full error')\n\nif plotlib in {'matplotlib', 'all'}:\n    try:\n        from qcodes.plots.qcmatplotlib import MatPlot\n    except Exception:\n        print('matplotlib plotting not supported, '\n              'try \"from qcodes.plots.qcmatplotlib import MatPlot\" '\n              'to see the full error')\n\n\nfrom qcodes.station import Station\nfrom qcodes.loops import Loop, active_loop, active_data_set\nfrom qcodes.measure import Measure\nfrom qcodes.actions import Task, Wait, BreakIf\nhaswebsockets = True\ntry:\n    import websockets\nexcept ImportError:\n    haswebsockets = False\nif haswebsockets:\n    from qcodes.monitor.monitor import Monitor\n\nfrom qcodes.data.data_set import DataSet, new_data, load_data\nfrom qcodes.data.location import FormatLocation\nfrom qcodes.data.data_array import DataArray\nfrom qcodes.data.format import Formatter\nfrom qcodes.data.gnuplot_format import GNUPlotFormat\nfrom qcodes.data.hdf5_format import HDF5Format\nfrom qcodes.data.io import DiskIO\n\nfrom qcodes.instrument.base import Instrument\nfrom qcodes.instrument.ip import IPInstrument\nfrom qcodes.instrument.visa import VisaInstrument\nfrom qcodes.instrument.channel import InstrumentChannel, ChannelList\n\nfrom qcodes.instrument.function import Function\nfrom qcodes.instrument.parameter import (\n    Parameter,\n    ArrayParameter,\n    MultiParameter,\n    StandardParameter,\n    ManualParameter,\n    combine,\n    CombinedParameter)\nfrom qcodes.instrument.sweep_values import SweepFixedValues, SweepValues\n\nfrom qcodes.utils import validators\nfrom qcodes.utils.zmq_helpers import Publisher\nfrom qcodes.instrument_drivers.test import test_instruments, test_instrument\n\nfrom qcodes.dataset.data_set import new_data_set, load_by_counter, load_by_id\nfrom qcodes.dataset.experiment_container import new_experiment, load_experiment, load_experiment_by_name, \\\n    load_last_experiment, experiments\nfrom qcodes.dataset.sqlite_settings import SQLiteSettings\nfrom qcodes.dataset.param_spec import ParamSpec\n\ntry:\n    get_ipython() # type: ignore # Check if we are in iPython\n    from qcodes.utils.magic import register_magic_class\n    _register_magic = config.core.get('register_magic', False)\n    if _register_magic is not False:\n        register_magic_class(magic_commands=_register_magic)\nexcept NameError:\n    pass\nexcept RuntimeError as e:\n    print(e)\n\n# ensure to close all instruments when interpreter is closed\nimport atexit\natexit.register(Instrument.close_all)\n\ndef test(**kwargs):\n    \"\"\"\n    Run QCoDeS tests. This requires the test requirements given\n    in test_requirements.txt to be installed.\n    All arguments are forwarded to pytest.main\n    \"\"\"\n    try:\n        import pytest\n    except ImportError:\n        print(\"Need pytest to run tests\")\n        return\n    args = ['--pyargs', 'qcodes.tests']\n    retcode = pytest.main(args, **kwargs)\n    return retcode\n\n\ntest.__test__ = False # type: ignore # Don't try to run this method as a test\n", "path": "qcodes/__init__.py"}]}