I am using ActiveX in my web application in one page, it is working properly in my PC, i am passing the connection string from the web page that has the activex in it as following:
This is the javascript code in the page that passing the connection string to the activex:
<script language="javascript" type="text/javascript">
function Connect() {
var doc = document.forms[0];
var PrinterControl = document.applets('PrinterObject1');
PrinterControl.UserText = document.form1.hdnConString.value + ',' + document.form1.hdnCategory.value + ',' + document.form1.hdnLoginID.value + ',' + document.form1.hdnPassword.value + ',' + document.form1.hdnCategoryType.value;
}
</script>
.
.
.
.
and in the activeX code i receive the connection string and other values as following:
public String UserText
{
get
{
return conString;
}
set
{
conString = value;
string[] arrID = conString.Split(',');
conStr = Convert.ToString(arrID[0]);
category = Convert.ToString(arrID[1]);
loginID = Convert.ToString(arrID[2]);
password = Convert.ToString(arrID[3]);
categoryType = Convert.ToString(arrID[4]);
}
}
Every thing working properly in my pc, but when i install this application in customer's server, the page that using activex generating error although it is working in my pc and i tested it in other pcs in my company over network still working ok, the customer using Windows2008 with sql server 2012.
The following is the error message generating in the page that using activex, when the page trying to load activex:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 = could not open a connection to SQL Server)
Please help
Thank you
Related
I've got an issue where I cannot connect to an on-premises SQL database through an Azure function app once it is published to Azure. However when I run it locally in Visual Studio Code, it works perfectly.
The purpose of the Function is to resize images that are stored in Azure blob storage to a thumbnail and store it in a table field <varbinary(max)>.
Here is the error message I get:
2020-12-15T15:33:52.058 [Information] A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
2020-12-15T15:33:52.093 [Error] Executed 'BlobTrigger_MQS_Resize' (Failed, Id=346672c6-820c-43f6-b950-d5059e44697e, Duration=19570ms)
Access is denied.
I'm connecting to the SQL database via SQL Login, which works perfectly. Connection String is in local.settings.json:
{
"IsEncrypted": false,
"Values": {
...,
"Connection_SQL_Database_MQS": "Data Source=MyServer;Initial Catalog=MyDB;User ID=MyUser;Password=MyPassword;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
}
}
The code (in C#) which I have simplified a bit to the core of the issue:
public static class BlobTrigger_MQS_Resize
{
[FunctionName("BlobTrigger_MQS_Resize")]
public static async Task Run([BlobTrigger("mqs-media/{name}", Connection = "hqdevstorage_STORAGE")]Stream input, string name, ILogger log)
{
log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {input.Length} Bytes");
try
{
var connectionString = Environment.GetEnvironmentVariable("Connection_SQL_Database_MQS", EnvironmentVariableTarget.Process);
using (var output = new MemoryStream())
using (Image<Rgba32> image = Image.Load(input))
using (SqlConnection conn = new SqlConnection(connectionString))
{
// Code that resizes images to 'output', this works also when published
image.Resize(...);
image.Save(output, encoder);
//PROBLEM IS HERE: Write resized image to SQL Database
conn.Open();
var query = "UPDATE dbo.MyTable"
+ " SET Blob = #output"
+ " WHERE File_Name = '" + name + "'";
using(SqlCommand cmd = new SqlCommand(query, conn))
{
cmd.Parameters.AddWithValue("#output", output);
var rows = await cmd.ExecuteNonQueryAsync();
log.LogInformation($"{rows} rows were updated");
}
}
}
catch (Exception ex)
{
log.LogInformation(ex.Message);
throw;
}
}
}
Can someone help me with this? I have no clue why it is working locally but not on Azure.
The server was not found or was not accessible.
This is a network connectivity issue, not a permissions issue. The Azure function cannot resolve your SQL Server's hostname into an IP address, and would not be able to connect to that IP address if it could.
Your function would need to access to an on-prem conected VNet or use a Hybrid Connection to reach your on-prem SQL Server.
see
https://learn.microsoft.com/en-us/azure/app-service/app-service-hybrid-connections
and
https://learn.microsoft.com/en-us/azure/azure-functions/functions-create-vnet
I am trying to write a program which interacts with my SQL Server database. I am programming in C# on Parallels on my Mac and SQL Server is running via Docker.
But I just can't connect. I am just getting the same error every time I try.
I have already tried to allow the remote access on SQL Server with:
EXEC sp_configure 'remote access', 1 ;
GO
RECONFIGURE ;
GO
but this does not solve my problem.
Here is my C# code:
main Class
Database database;
public Form1()
{
InitializeComponent();
database = new Database("localhost\\MSSQLSERVER", "user1", "topsecret", "master"); // \
}
private void connect_button_Click(object sender, EventArgs e)
{
database.Connect();
}
Database class:
class Database
{
SqlConnectionStringBuilder builder;
SqlConnection connection;
public Database(string source, string userid, string password, string initialcatalog){
this.builder = new SqlConnectionStringBuilder();
this.builder.DataSource = source;
this.builder.UserID = userid;
this.builder.Password = password;
this.builder.InitialCatalog = initialcatalog;
}
public void Connect()
{
try
{
// Connect to SQL
Console.WriteLine("Connecting to SQL Server ... ");
this.connection = new SqlConnection(this.builder.ConnectionString);
connection.Open();
Console.WriteLine("Connected");
}
catch(SqlException sqle)
{
Console.WriteLine(sqle.Message);
}
}
}
And I am always getting this error:
Network-related or instance-specific error when connecting to SQL Server. The server was not found or can not be accessed. Verify that the instance name is correct and that SQL Server allows remote connections. (provider: SQL Network Interfaces, error: 25 - connection string invalid)
The MSSQLSERVER is the instance name of the unnamed, default instance on your machine - you must not use this in the connection string.
Instead, try this line of code:
database = new Database("localhost", "user1", "topsecret", "master");
Just specify no explicit instance name at all - just localhost (or (local), or .) for the current machine - that's all you need!
It was Problem with Parallels, because Paralles can not access to localhost. So i had to define the IP from Parallels in Visual Studio like this:
database = new Database("10.211.55.2", "user1", "topsecret", "Time");
This question already has answers here:
Cannot Connect to Server - A network-related or instance-specific error
(54 answers)
Closed 4 years ago.
I'm trying to run this sample codes - https://marcominerva.wordpress.com/2017/10/25/using-sqlclient-apis-and-dapper-with-fall-creators-update-sdk/
I imported their database as well but not sure why it keep appearing System.Data.SqlClient.SqlException.
enter image description here
I already clean and build my solution and it doesn't work still
public sealed partial class MainPage : Page
{
// public string ConnectionString { get; set; } =
private string connectionString =#"Data Source=LAPTOP-IQQCR1C1;Initial Catalog = DatabaseDemo; Persist Security Info=True;User ID = xxxx Password=xxxxxxx";
//public string ConnectionString { get => connectionString; set => connectionString = value; }
public MainPage()
{
this.InitializeComponent();
}
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
var cities = await GetCitiesAsync(); //THIS LINE OF CODES GIVE THE SYSTEM.DATA.SQLCLIENT.SQLEXCEPTION
CitiesComboBox.ItemsSource = cities;
CitiesComboBox.SelectedIndex = 0;
base.OnNavigatedTo(e);
}
It still runs. But can't read the data for the dropdown and when searched, cannot read images from database.
Output:
sample
What I want:
sample
The SqlException with the error 40 means, that you can't connect to your SQL Server.
It seems that you have a wrong configuration on your server or the server is offline.
check if the service "SQL Server (INSTANCENAME)" is running on your machine
check in the Configuration Manager (SQL Server) if TCP/IP is enabled
check in the SQL Management Studio if the Server properties if remote connections are enabled.
if the SQL Server is not on your local machine, make sure the ports for communication are opened
Here you can find a detailed description on how to do the steps above.
I'm a student doing an assignment which is an appointment system, I'm using Management Studio for the database, I detached it and linked Visual Studio with the .mdf file.
I can't find where the error is and never solved this type of error before.
Code:
DataClasses1DataContext db = new DataClasses1DataContext();
public frmAccountCreation()
{
InitializeComponent();
}
private void btnCreateAccount_Click(object sender, EventArgs e)
{
string email = txtEmail.ToString();
string fullname = txtFullname.ToString();
string username = txtUsername.ToString();
string password = txtPassword.ToString();
int userlevel;
string contactnumber =txtContactNumber.ToString();
if(ckbAdmin.Checked)
{
userlevel = 1;
}
else
{
userlevel = 0;
}
tblUserAccount account = new tblUserAccount
{
Username = username,
Passcode = password,
UserPrivelage = userlevel
};
tblVet vet = new tblVet
{
Email = email,
FullName = fullname,
ContactNumber = contactnumber
};
db.tblUserAccounts.InsertOnSubmit(account);
db.tblVets.InsertOnSubmit(vet);
db.SubmitChanges();//Error Is here
}
}
Error:
An unhandled exception of type 'System.Data.SqlClient.SqlException'
occurred in System.Data.Linq.dll
Additional information: A network-related or instance-specific error
occurred while establishing a connection to SQL Server. The server was
not found or was not accessible. Verify that the instance name is
correct and that SQL
Looking at this line:
DataClasses1DataContext db = new DataClasses1DataContext("C:\\Users\\Luke\\Desktop\\OOP Assignment\\OOP_Database.mdf");
You are trying to open the MDF file directly. You cannot do that. You need a running SQL server instance (which can be on your development machine, like SQL Express), and you will need a connection string to connect to that server.
I solved the problem by uninstalling everything related to visual studio community 2015 and my antivirus avg after i reinstalled everything worked perfectly fine
It seems your SQL Server Service is not running.
In Windows, search for "Services" and there should be a Windows application with the same name.
In the application keep scrolling untill you find "SQL Server (MSSQLSERVER)" and make sure it's running.
I want to create a simple tool that connect to SQL Server then list all databases, and after user selects one of those databases, the tool will perform some SQL scripts on it.
Below is a method that should return a DataTable contains all my databases;
I send to it sqlServerIp as first parameter like 10.10.20.30 ip address not server name.
Also I didn't specify a SQL Server instance.
private DataTable GetSqlServerDatabases(String sqlServer, bool isWindowsAuth, String login, String password)
{
String connectionString;
DataTable databases;
if (isWindowsAuth)
{
connectionString = "Data Source=" + sqlServer + ",1433;Network Library=DBMSSOCN; Integrated Security=True;";
}
else
{
connectionString = "Data Source=" + sqlServer + ",1433;Network Library=DBMSSOCN;" + "User id=" + login + ";Password=" + password + ";";
}
try
{
using (var con = new SqlConnection(connectionString))
{
con.Open();
databases = con.GetSchema("Databases");
foreach (DataRow database in databases.Rows)
{
String databaseName = database.Field<String>("database_name");
short dbID = database.Field<short>("dbid");
DateTime creationDate = database.Field<DateTime>("create_date");
}
}
}
catch(Exception ex)
{
databases = null;
MessageBox.Show(ex.Message.ToString());
}
return databases;
}
When I try to call the method on more than one server I faced an exception:
Login failed. The login is from an untrusted domain and cannot be used with Windows authentication.
or
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible.
I used connection string with Network Library=DBMSSOCN; after searching here on SO and web so I don't know what is the wrong with this method.
Remove Integrated Security parameter. This parameter is for trusted connections.
More samples on http://www.connectionstrings.com/sql-server