Skip to content

Commit 9df6c87

Browse files
committed
update .net drivers snippet
1 parent 8774e44 commit 9df6c87

File tree

1 file changed

+6
-37
lines changed

1 file changed

+6
-37
lines changed

documentation/connect-drivers-dotnet.adoc

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,12 @@ link:https://www.nuget.org/packages/Neo4j.Driver/.
99

1010
[source, csharp, role=nocollapse]
1111
----
12-
public class HelloWorldExample : IDisposable
13-
{
14-
private readonly IDriver _driver;
12+
using Neo4j.Driver;
1513
16-
public HelloWorldExample(string uri, string user, string password)
17-
{
18-
_driver = GraphDatabase.Driver(uri, AuthTokens.Basic(user, password));
19-
}
14+
const string uri = "{neo4j-database-uri}";
15+
const string user = "<Username>";
16+
const string password = "<Password>";
2017
21-
public void PrintGreeting(string message)
22-
{
23-
using var session = _driver.Session();
24-
var greeting = session.ExecuteWrite(
25-
tx =>
26-
{
27-
var result = tx.Run(
28-
"CREATE (a:Greeting) " +
29-
"SET a.message = $message " +
30-
"RETURN a.message + ', from node ' + id(a)",
31-
new { message });
32-
33-
return result.Single()[0].As<string>();
34-
});
35-
36-
Console.WriteLine(greeting);
37-
}
38-
39-
public void Dispose()
40-
{
41-
_driver?.Dispose();
42-
}
43-
44-
public static void Main()
45-
{
46-
using var greeter = new HelloWorldExample("{neo4j-database-uri}", "<Username>", "<Password>");
47-
48-
greeter.PrintGreeting("hello, world");
49-
}
50-
}
18+
await using var driver = GraphDatabase.Driver(uri, AuthTokens.Basic(user, password));
19+
await driver.VerifyConnectivityAsync();
5120
----

0 commit comments

Comments
 (0)