Azure Functions v2 Connectionstring from application settings Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Is there a better way to do optional function parameters in JavaScript?What's the difference between a method and a function?What is the naming convention in Python for variable and function names?How to get a function name as a string in Python?var functionName = function() vs function functionName() Set a default parameter value for a JavaScript functionWhat does the exclamation mark do before the function?Pass a JavaScript function as parameterJavaScript plus sign in front of function nameAdding .edmx connectionString to Azure “Application Settings”
All ASCII characters with a given bit count
What ability score does a Hexblade's Pact Weapon use for attack and damage when wielded by another character?
Is there any hidden 'W' sound after 'comment' in : Comment est-elle?
As an international instructor, should I openly talk about my accent?
How to open locks without disable device?
Why isn't everyone flabbergasted about Bran's "gift"?
What is the best way to deal with NPC-NPC combat?
Israeli soda type drink
Did the Roman Empire have penal colonies?
How to use @AuraEnabled base class method in Lightning Component?
What is the least dense liquid under normal conditions?
How can I wire a 9-position switch so that each position turns on one more LED than the one before?
Map material from china not allowed to leave the country
My admission is revoked after accepting the admission offer
Error: Syntax error. Missing ')' for CASE Statement
PIC mathematical operations weird problem
What's the difference between using dependency injection with a container and using a service locator?
Does Feeblemind produce an ongoing magical effect that can be dispelled?
How would I use different systems of magic when they are capable of the same effects?
Are these square matrices always diagonalisable?
Is it OK if I do not take the receipt in Germany?
Can you stand up from being prone using Skirmisher outside of your turn?
Why did Israel vote against lifting the American embargo on Cuba?
What is /etc/mtab in Linux?
Azure Functions v2 Connectionstring from application settings
Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Is there a better way to do optional function parameters in JavaScript?What's the difference between a method and a function?What is the naming convention in Python for variable and function names?How to get a function name as a string in Python?var functionName = function() vs function functionName() Set a default parameter value for a JavaScript functionWhat does the exclamation mark do before the function?Pass a JavaScript function as parameterJavaScript plus sign in front of function nameAdding .edmx connectionString to Azure “Application Settings”
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have made a simple Azure Functions v2 Web Service that connects to an Azure SQL database, runs a stored procedure with 3 parameters and returns the result as JSON output. It works as it is now (with the connectionstring in the run.csx file).
But how do I get it to get the connectionstring from Applications Settings?
I have tried various guides both here and other places. But all I can find is a long list of references and a whole bunch of code I need to add. I have followed the guides to the letter (also set the values in App Settings), but it just wont work. I'm rather new to C#, so it might be I just don't understand what I'm supposed to do.
Anyways this is my code and the suggested fix, as far as I'm able to tell:
#r "Newtonsoft.Json"
#r "System.Data"
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using System.Data;
using System.Data.SqlClient;
public static async Task<ActionResult> Run(HttpRequest req, ILogger log)
log.LogInformation("C# HTTP trigger function processed a request.");
string login = req.Query["login"];
string pwd = req.Query["password"];
string TransID = req.Query["TransID"];
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
login = login ?? data?.login;
pwd = pwd ?? data?.password;
TransID = TransID ?? data?.TransID;
var cnnString = "Server=MyServer;Database=WebServices;User Id=MyUser;Password=MyPassword;Encrypt=True;";
try
DataTable table = new DataTable();
SqlConnection connection = new SqlConnection(cnnString);
SqlCommand cmd = new SqlCommand("sp_GetRegRW", connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@Login", login));
cmd.Parameters.Add(new SqlParameter("@Password", pwd));
cmd.Parameters.Add(new SqlParameter("@TransID", TransID));
await connection.OpenAsync();
using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
adapter.Fill(table);
return (ActionResult)new OkObjectResult(JsonConvert.SerializeObject(table));
catch (SqlException sqlex)
return (ActionResult)new OkObjectResult($"The following SqlException happened: sqlex.Message");
catch (Exception ex)
return (ActionResult)new OkObjectResult($"The following Exception happened: ex.Message");
suggested solution:
#r "Newtonsoft.Json"
#r "System.Data"
#r "Microsoft.Extensions.Configuration"
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Extensions.Configuration;
public static async Task<ActionResult> Run(HttpRequest req, ILogger log, ExecutionContext context)
var config = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
var cnnString =config.GetConnectionString("connWS");
var setting1 = config["Setting1"];
log.LogInformation(cnnString);
log.LogInformation(setting1);
log.LogInformation("C# HTTP trigger function processed a request.");
string login = req.Query["login"];
string pwd = req.Query["password"];
string TransID = req.Query["TransID"];
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
login = login ?? data?.login;
pwd = pwd ?? data?.password;
TransID = TransID ?? data?.TransID;
try
DataTable table = new DataTable();
SqlConnection connection = new SqlConnection(cnnString);
SqlCommand cmd = new SqlCommand("sp_GetRegRW", connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@Login", login));
cmd.Parameters.Add(new SqlParameter("@Password", pwd));
cmd.Parameters.Add(new SqlParameter("@TransID", TransID));
await connection.OpenAsync();
using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
adapter.Fill(table);
return (ActionResult)new OkObjectResult(JsonConvert.SerializeObject(table));
catch (SqlException sqlex)
return (ActionResult)new OkObjectResult($"The following SqlException happened: sqlex.Message");
catch (Exception ex)
return (ActionResult)new OkObjectResult($"The following Exception happened: ex.Message");
function azure connection-string
add a comment |
I have made a simple Azure Functions v2 Web Service that connects to an Azure SQL database, runs a stored procedure with 3 parameters and returns the result as JSON output. It works as it is now (with the connectionstring in the run.csx file).
But how do I get it to get the connectionstring from Applications Settings?
I have tried various guides both here and other places. But all I can find is a long list of references and a whole bunch of code I need to add. I have followed the guides to the letter (also set the values in App Settings), but it just wont work. I'm rather new to C#, so it might be I just don't understand what I'm supposed to do.
Anyways this is my code and the suggested fix, as far as I'm able to tell:
#r "Newtonsoft.Json"
#r "System.Data"
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using System.Data;
using System.Data.SqlClient;
public static async Task<ActionResult> Run(HttpRequest req, ILogger log)
log.LogInformation("C# HTTP trigger function processed a request.");
string login = req.Query["login"];
string pwd = req.Query["password"];
string TransID = req.Query["TransID"];
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
login = login ?? data?.login;
pwd = pwd ?? data?.password;
TransID = TransID ?? data?.TransID;
var cnnString = "Server=MyServer;Database=WebServices;User Id=MyUser;Password=MyPassword;Encrypt=True;";
try
DataTable table = new DataTable();
SqlConnection connection = new SqlConnection(cnnString);
SqlCommand cmd = new SqlCommand("sp_GetRegRW", connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@Login", login));
cmd.Parameters.Add(new SqlParameter("@Password", pwd));
cmd.Parameters.Add(new SqlParameter("@TransID", TransID));
await connection.OpenAsync();
using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
adapter.Fill(table);
return (ActionResult)new OkObjectResult(JsonConvert.SerializeObject(table));
catch (SqlException sqlex)
return (ActionResult)new OkObjectResult($"The following SqlException happened: sqlex.Message");
catch (Exception ex)
return (ActionResult)new OkObjectResult($"The following Exception happened: ex.Message");
suggested solution:
#r "Newtonsoft.Json"
#r "System.Data"
#r "Microsoft.Extensions.Configuration"
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Extensions.Configuration;
public static async Task<ActionResult> Run(HttpRequest req, ILogger log, ExecutionContext context)
var config = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
var cnnString =config.GetConnectionString("connWS");
var setting1 = config["Setting1"];
log.LogInformation(cnnString);
log.LogInformation(setting1);
log.LogInformation("C# HTTP trigger function processed a request.");
string login = req.Query["login"];
string pwd = req.Query["password"];
string TransID = req.Query["TransID"];
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
login = login ?? data?.login;
pwd = pwd ?? data?.password;
TransID = TransID ?? data?.TransID;
try
DataTable table = new DataTable();
SqlConnection connection = new SqlConnection(cnnString);
SqlCommand cmd = new SqlCommand("sp_GetRegRW", connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@Login", login));
cmd.Parameters.Add(new SqlParameter("@Password", pwd));
cmd.Parameters.Add(new SqlParameter("@TransID", TransID));
await connection.OpenAsync();
using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
adapter.Fill(table);
return (ActionResult)new OkObjectResult(JsonConvert.SerializeObject(table));
catch (SqlException sqlex)
return (ActionResult)new OkObjectResult($"The following SqlException happened: sqlex.Message");
catch (Exception ex)
return (ActionResult)new OkObjectResult($"The following Exception happened: ex.Message");
function azure connection-string
1
Have you looked at this? docs.microsoft.com/en-us/azure/azure-functions/…
– Brad Patton
Mar 22 at 15:56
thanks for the link Brad. I didn't code it in VS locally and publish it. I just typed the code directly in the online editor. I have added the ADO.net connectionstring from the DB to application parameters and called it connWS. when I call the connectionstring as suggested (var cnnString = Environment.GetEnvironmentVariable("connWS");) I get the following error: The ConnectionString property has not been initialized.
– Jacob.Christensen
Mar 22 at 22:51
add a comment |
I have made a simple Azure Functions v2 Web Service that connects to an Azure SQL database, runs a stored procedure with 3 parameters and returns the result as JSON output. It works as it is now (with the connectionstring in the run.csx file).
But how do I get it to get the connectionstring from Applications Settings?
I have tried various guides both here and other places. But all I can find is a long list of references and a whole bunch of code I need to add. I have followed the guides to the letter (also set the values in App Settings), but it just wont work. I'm rather new to C#, so it might be I just don't understand what I'm supposed to do.
Anyways this is my code and the suggested fix, as far as I'm able to tell:
#r "Newtonsoft.Json"
#r "System.Data"
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using System.Data;
using System.Data.SqlClient;
public static async Task<ActionResult> Run(HttpRequest req, ILogger log)
log.LogInformation("C# HTTP trigger function processed a request.");
string login = req.Query["login"];
string pwd = req.Query["password"];
string TransID = req.Query["TransID"];
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
login = login ?? data?.login;
pwd = pwd ?? data?.password;
TransID = TransID ?? data?.TransID;
var cnnString = "Server=MyServer;Database=WebServices;User Id=MyUser;Password=MyPassword;Encrypt=True;";
try
DataTable table = new DataTable();
SqlConnection connection = new SqlConnection(cnnString);
SqlCommand cmd = new SqlCommand("sp_GetRegRW", connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@Login", login));
cmd.Parameters.Add(new SqlParameter("@Password", pwd));
cmd.Parameters.Add(new SqlParameter("@TransID", TransID));
await connection.OpenAsync();
using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
adapter.Fill(table);
return (ActionResult)new OkObjectResult(JsonConvert.SerializeObject(table));
catch (SqlException sqlex)
return (ActionResult)new OkObjectResult($"The following SqlException happened: sqlex.Message");
catch (Exception ex)
return (ActionResult)new OkObjectResult($"The following Exception happened: ex.Message");
suggested solution:
#r "Newtonsoft.Json"
#r "System.Data"
#r "Microsoft.Extensions.Configuration"
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Extensions.Configuration;
public static async Task<ActionResult> Run(HttpRequest req, ILogger log, ExecutionContext context)
var config = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
var cnnString =config.GetConnectionString("connWS");
var setting1 = config["Setting1"];
log.LogInformation(cnnString);
log.LogInformation(setting1);
log.LogInformation("C# HTTP trigger function processed a request.");
string login = req.Query["login"];
string pwd = req.Query["password"];
string TransID = req.Query["TransID"];
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
login = login ?? data?.login;
pwd = pwd ?? data?.password;
TransID = TransID ?? data?.TransID;
try
DataTable table = new DataTable();
SqlConnection connection = new SqlConnection(cnnString);
SqlCommand cmd = new SqlCommand("sp_GetRegRW", connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@Login", login));
cmd.Parameters.Add(new SqlParameter("@Password", pwd));
cmd.Parameters.Add(new SqlParameter("@TransID", TransID));
await connection.OpenAsync();
using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
adapter.Fill(table);
return (ActionResult)new OkObjectResult(JsonConvert.SerializeObject(table));
catch (SqlException sqlex)
return (ActionResult)new OkObjectResult($"The following SqlException happened: sqlex.Message");
catch (Exception ex)
return (ActionResult)new OkObjectResult($"The following Exception happened: ex.Message");
function azure connection-string
I have made a simple Azure Functions v2 Web Service that connects to an Azure SQL database, runs a stored procedure with 3 parameters and returns the result as JSON output. It works as it is now (with the connectionstring in the run.csx file).
But how do I get it to get the connectionstring from Applications Settings?
I have tried various guides both here and other places. But all I can find is a long list of references and a whole bunch of code I need to add. I have followed the guides to the letter (also set the values in App Settings), but it just wont work. I'm rather new to C#, so it might be I just don't understand what I'm supposed to do.
Anyways this is my code and the suggested fix, as far as I'm able to tell:
#r "Newtonsoft.Json"
#r "System.Data"
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using System.Data;
using System.Data.SqlClient;
public static async Task<ActionResult> Run(HttpRequest req, ILogger log)
log.LogInformation("C# HTTP trigger function processed a request.");
string login = req.Query["login"];
string pwd = req.Query["password"];
string TransID = req.Query["TransID"];
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
login = login ?? data?.login;
pwd = pwd ?? data?.password;
TransID = TransID ?? data?.TransID;
var cnnString = "Server=MyServer;Database=WebServices;User Id=MyUser;Password=MyPassword;Encrypt=True;";
try
DataTable table = new DataTable();
SqlConnection connection = new SqlConnection(cnnString);
SqlCommand cmd = new SqlCommand("sp_GetRegRW", connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@Login", login));
cmd.Parameters.Add(new SqlParameter("@Password", pwd));
cmd.Parameters.Add(new SqlParameter("@TransID", TransID));
await connection.OpenAsync();
using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
adapter.Fill(table);
return (ActionResult)new OkObjectResult(JsonConvert.SerializeObject(table));
catch (SqlException sqlex)
return (ActionResult)new OkObjectResult($"The following SqlException happened: sqlex.Message");
catch (Exception ex)
return (ActionResult)new OkObjectResult($"The following Exception happened: ex.Message");
suggested solution:
#r "Newtonsoft.Json"
#r "System.Data"
#r "Microsoft.Extensions.Configuration"
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Extensions.Configuration;
public static async Task<ActionResult> Run(HttpRequest req, ILogger log, ExecutionContext context)
var config = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
var cnnString =config.GetConnectionString("connWS");
var setting1 = config["Setting1"];
log.LogInformation(cnnString);
log.LogInformation(setting1);
log.LogInformation("C# HTTP trigger function processed a request.");
string login = req.Query["login"];
string pwd = req.Query["password"];
string TransID = req.Query["TransID"];
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
login = login ?? data?.login;
pwd = pwd ?? data?.password;
TransID = TransID ?? data?.TransID;
try
DataTable table = new DataTable();
SqlConnection connection = new SqlConnection(cnnString);
SqlCommand cmd = new SqlCommand("sp_GetRegRW", connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@Login", login));
cmd.Parameters.Add(new SqlParameter("@Password", pwd));
cmd.Parameters.Add(new SqlParameter("@TransID", TransID));
await connection.OpenAsync();
using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
adapter.Fill(table);
return (ActionResult)new OkObjectResult(JsonConvert.SerializeObject(table));
catch (SqlException sqlex)
return (ActionResult)new OkObjectResult($"The following SqlException happened: sqlex.Message");
catch (Exception ex)
return (ActionResult)new OkObjectResult($"The following Exception happened: ex.Message");
function azure connection-string
function azure connection-string
asked Mar 22 at 15:53
Jacob.ChristensenJacob.Christensen
32
32
1
Have you looked at this? docs.microsoft.com/en-us/azure/azure-functions/…
– Brad Patton
Mar 22 at 15:56
thanks for the link Brad. I didn't code it in VS locally and publish it. I just typed the code directly in the online editor. I have added the ADO.net connectionstring from the DB to application parameters and called it connWS. when I call the connectionstring as suggested (var cnnString = Environment.GetEnvironmentVariable("connWS");) I get the following error: The ConnectionString property has not been initialized.
– Jacob.Christensen
Mar 22 at 22:51
add a comment |
1
Have you looked at this? docs.microsoft.com/en-us/azure/azure-functions/…
– Brad Patton
Mar 22 at 15:56
thanks for the link Brad. I didn't code it in VS locally and publish it. I just typed the code directly in the online editor. I have added the ADO.net connectionstring from the DB to application parameters and called it connWS. when I call the connectionstring as suggested (var cnnString = Environment.GetEnvironmentVariable("connWS");) I get the following error: The ConnectionString property has not been initialized.
– Jacob.Christensen
Mar 22 at 22:51
1
1
Have you looked at this? docs.microsoft.com/en-us/azure/azure-functions/…
– Brad Patton
Mar 22 at 15:56
Have you looked at this? docs.microsoft.com/en-us/azure/azure-functions/…
– Brad Patton
Mar 22 at 15:56
thanks for the link Brad. I didn't code it in VS locally and publish it. I just typed the code directly in the online editor. I have added the ADO.net connectionstring from the DB to application parameters and called it connWS. when I call the connectionstring as suggested (var cnnString = Environment.GetEnvironmentVariable("connWS");) I get the following error: The ConnectionString property has not been initialized.
– Jacob.Christensen
Mar 22 at 22:51
thanks for the link Brad. I didn't code it in VS locally and publish it. I just typed the code directly in the online editor. I have added the ADO.net connectionstring from the DB to application parameters and called it connWS. when I call the connectionstring as suggested (var cnnString = Environment.GetEnvironmentVariable("connWS");) I get the following error: The ConnectionString property has not been initialized.
– Jacob.Christensen
Mar 22 at 22:51
add a comment |
1 Answer
1
active
oldest
votes
In function v2, you should use Environment.GetEnvironmentVariable("string_name",EnvironmentVariableTarget.Process)
to get values from Application settings and connection strings.
Note: When use the above method, the first parameter depends on the Type. It means that when the type of the connection string is SQLAZURE
, then the first parameter should be SQLAZURE + CONNSTR + _stringName
.
The screenshot is as below:
The code sample:
//for connection string
string connStr = Environment.GetEnvironmentVariable("SQLAZURECONNSTR_sqldb_connection",EnvironmentVariableTarget.Process);
log.LogInformation("the connection string is: " + connStr);
And the result snapshot:
I get the following error: The ConnectionString property has not been initialized.
You should probably create an instance of SqlConnection, with your connection string and open this connection before try to make any command.
SqlConnection con = new SqlConnection("connStr");
await con.OpenAsync();
Thank you Joey! all I needed was the prefix to the connectionstring-name (SQLAZURECONNSTR_). now it runs smoothly. Funny i never saw anything about it, anywhere else I have looked.
– Jacob.Christensen
Mar 25 at 21:11
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55303414%2fazure-functions-v2-connectionstring-from-application-settings%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
In function v2, you should use Environment.GetEnvironmentVariable("string_name",EnvironmentVariableTarget.Process)
to get values from Application settings and connection strings.
Note: When use the above method, the first parameter depends on the Type. It means that when the type of the connection string is SQLAZURE
, then the first parameter should be SQLAZURE + CONNSTR + _stringName
.
The screenshot is as below:
The code sample:
//for connection string
string connStr = Environment.GetEnvironmentVariable("SQLAZURECONNSTR_sqldb_connection",EnvironmentVariableTarget.Process);
log.LogInformation("the connection string is: " + connStr);
And the result snapshot:
I get the following error: The ConnectionString property has not been initialized.
You should probably create an instance of SqlConnection, with your connection string and open this connection before try to make any command.
SqlConnection con = new SqlConnection("connStr");
await con.OpenAsync();
Thank you Joey! all I needed was the prefix to the connectionstring-name (SQLAZURECONNSTR_). now it runs smoothly. Funny i never saw anything about it, anywhere else I have looked.
– Jacob.Christensen
Mar 25 at 21:11
add a comment |
In function v2, you should use Environment.GetEnvironmentVariable("string_name",EnvironmentVariableTarget.Process)
to get values from Application settings and connection strings.
Note: When use the above method, the first parameter depends on the Type. It means that when the type of the connection string is SQLAZURE
, then the first parameter should be SQLAZURE + CONNSTR + _stringName
.
The screenshot is as below:
The code sample:
//for connection string
string connStr = Environment.GetEnvironmentVariable("SQLAZURECONNSTR_sqldb_connection",EnvironmentVariableTarget.Process);
log.LogInformation("the connection string is: " + connStr);
And the result snapshot:
I get the following error: The ConnectionString property has not been initialized.
You should probably create an instance of SqlConnection, with your connection string and open this connection before try to make any command.
SqlConnection con = new SqlConnection("connStr");
await con.OpenAsync();
Thank you Joey! all I needed was the prefix to the connectionstring-name (SQLAZURECONNSTR_). now it runs smoothly. Funny i never saw anything about it, anywhere else I have looked.
– Jacob.Christensen
Mar 25 at 21:11
add a comment |
In function v2, you should use Environment.GetEnvironmentVariable("string_name",EnvironmentVariableTarget.Process)
to get values from Application settings and connection strings.
Note: When use the above method, the first parameter depends on the Type. It means that when the type of the connection string is SQLAZURE
, then the first parameter should be SQLAZURE + CONNSTR + _stringName
.
The screenshot is as below:
The code sample:
//for connection string
string connStr = Environment.GetEnvironmentVariable("SQLAZURECONNSTR_sqldb_connection",EnvironmentVariableTarget.Process);
log.LogInformation("the connection string is: " + connStr);
And the result snapshot:
I get the following error: The ConnectionString property has not been initialized.
You should probably create an instance of SqlConnection, with your connection string and open this connection before try to make any command.
SqlConnection con = new SqlConnection("connStr");
await con.OpenAsync();
In function v2, you should use Environment.GetEnvironmentVariable("string_name",EnvironmentVariableTarget.Process)
to get values from Application settings and connection strings.
Note: When use the above method, the first parameter depends on the Type. It means that when the type of the connection string is SQLAZURE
, then the first parameter should be SQLAZURE + CONNSTR + _stringName
.
The screenshot is as below:
The code sample:
//for connection string
string connStr = Environment.GetEnvironmentVariable("SQLAZURECONNSTR_sqldb_connection",EnvironmentVariableTarget.Process);
log.LogInformation("the connection string is: " + connStr);
And the result snapshot:
I get the following error: The ConnectionString property has not been initialized.
You should probably create an instance of SqlConnection, with your connection string and open this connection before try to make any command.
SqlConnection con = new SqlConnection("connStr");
await con.OpenAsync();
edited Mar 25 at 7:08
answered Mar 25 at 3:10
Joey CaiJoey Cai
6,1051211
6,1051211
Thank you Joey! all I needed was the prefix to the connectionstring-name (SQLAZURECONNSTR_). now it runs smoothly. Funny i never saw anything about it, anywhere else I have looked.
– Jacob.Christensen
Mar 25 at 21:11
add a comment |
Thank you Joey! all I needed was the prefix to the connectionstring-name (SQLAZURECONNSTR_). now it runs smoothly. Funny i never saw anything about it, anywhere else I have looked.
– Jacob.Christensen
Mar 25 at 21:11
Thank you Joey! all I needed was the prefix to the connectionstring-name (SQLAZURECONNSTR_). now it runs smoothly. Funny i never saw anything about it, anywhere else I have looked.
– Jacob.Christensen
Mar 25 at 21:11
Thank you Joey! all I needed was the prefix to the connectionstring-name (SQLAZURECONNSTR_). now it runs smoothly. Funny i never saw anything about it, anywhere else I have looked.
– Jacob.Christensen
Mar 25 at 21:11
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55303414%2fazure-functions-v2-connectionstring-from-application-settings%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Have you looked at this? docs.microsoft.com/en-us/azure/azure-functions/…
– Brad Patton
Mar 22 at 15:56
thanks for the link Brad. I didn't code it in VS locally and publish it. I just typed the code directly in the online editor. I have added the ADO.net connectionstring from the DB to application parameters and called it connWS. when I call the connectionstring as suggested (var cnnString = Environment.GetEnvironmentVariable("connWS");) I get the following error: The ConnectionString property has not been initialized.
– Jacob.Christensen
Mar 22 at 22:51