C# Remote Connectionstring SQL Server - c#

ich got some problems connecting to the database stored on a server in the local network. I tryed almost everything, but nothing helps.
I got 2 Databases, MYSQL and MSSQL.
Configuration:
Server: 192.168.0.198
MYSQL Port: 3306
MSSQL Port: 1433
If i connect manuelly in Visual Studio it works, but if i copy the ConnectionString from the properties, it only connects to the MYSQL Database and not the MSSQL (same login, same password, same ip adress, but ports are different)
In Visual Studio is P3B-Server\P3BMSSQL for the server and db_Software for the database
Visual Studio Properties:
"Data Source=P3B-Server;Initial Catalog=db_Software;User ID=myUser;Password=mypassword"
But it doesnt work :/
I tryed
"Data Source=P3B-Server..."
#"Data Source=P3B-Server\P3BMSSQL..."
"Data Source=192.168.0.198,1433..."
"Data Source=tcp:192.168.0.198,1433..."
Still no connection to MSSQL Server, only MYSQL Server.
I`m connecting with HeidiSQL to both Databases and got
"Microsoft SQL Server (TCP/IP, experimental)" with 192.168.0.198, Port 1433,
user=myUser and Password=mypassword" for the MSSQL Server and there it works.
Checked "connectionstrings.com", but no solution works for me.
PS: Other side is an ASP.NET application, which connects with
<connectionStrings>
<add name="ApplicationServices" connectionString="Data Source=192.168.0.198;Initial Catalog=db_Software;User Id=myUser;Password=myPassword;" providerName="System.Data.SqlClient"/>
</connectionStrings>
(stored in Web.config) to the database.
I need exact this for my C# application as a Connectionstring.
Please help me. Thanks !

<connectionStrings>
<add name="ApplicationServices" connectionString="Data Source=192.168.0.198\P3BMSSQL;Initial Catalog=db_Software;User Id=myUser;Password=myPassword;" providerName="System.Data.SqlClient"/>
</connectionStrings>

Related

Aws RDS Connected via MySQLl Workbench but not Visual Studio

I have an AWS RDS instance which I'm successfully connecting to via MySQL Workbench. However, I cannot connect to the RDS in Visual Studio (via connection string in Web.config) using the same credentials. Here, the connection times-out when I run update-database and gives: Error Number:53,State:0,Class:20, and error: 40 - Could not open a connection to SQL Server.
My connection string is in the following format:
<add name="ConnectionName" connectionString="Data Source=[NAME].[REGION].rds.amazonaws.com; database=[DB_NAME]; user=[USERNAME]; password=[PASSWORD]; Integrated Security=True" providerName="System.Data.SqlClient" />
Is there any issue with this connection string, or could I be missing something else entirely?
I don't have access to AWS Workbench, so I can't check any of the RDS settings, as the database was setup for me.
System.Data.SQLClient expects the other end to be a Microsoft SQL Server database, not a MySQL database. Instead you'll need to download and install a MySQL Managed Data provider and configure that as your provider:
See:
https://dev.mysql.com/downloads/connector/net/5.0.html
https://dev.mysql.com/doc/connector-net/en/connector-net-connection-options.html
Simplest way to get the MySQL Client distributed with your application is probably to use the NuGet package.
Example:
<add name="MySqlConnectionString"
connectionString="server=127.0.0.1;User Id=root;password=bpdash;database=sample"
providerName="MySql.Data.MySqlClient" />

Cant find my EF code first database

I am doing Microsoft's MVC getting started tutorial:
Getting Started with Entity Framework 6 Code First using MVC 5.
This includes the creation of a code first database.
It all works fine, but I am not able to find my database.
This is my ConnectionString:
<add name="MovieDBContext" connectionString="Data Source=.\SQLEXPRESS; Integrated Security=True" providerName="System.Data.SqlClient"/>
If I debug my index Method the connection is as follow:
Data Source=.\SQLEXPRESS; Integrated Security=True
But there is no Database in my SQLEXPRESS Instance, I have checked it with SQL Server Management Studio.
I also cant find anything if I search my filesystem for *.mdf.
App_Data in my Project is Empty...
But all CRUD operations are working fine, there has to be something.
The only way I can see that table is to connect to .\SQLEXPRESS via the Visual Studio Server Explorer. But where is this physically located? Why cant I see the table if I connect to .\SQLEXPRESS via SQL Server Management Studio?
Any idea?
You didn't specify the Initial Catalog in your connection string so probably you are using the Master database.
You need to specify the Initial catalog like this:
<add name="MovieDBContext"
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=yourDBName;Integrated Security=True"
providerName="System.Data.SqlClient"/>

Connecting to SQL server via TCP/IP, not NP

As I found out, my SQL server has disabled Named Pipes, but enabled TCP/IP (and it will stay this way). Now I am trying to connect from the visual studio to the database, but with no luck.
I've tried so far:
string connstring = "Data Source=192.168.1.1:1433 ;Initial Catalog=np-sparcsn4-custom;Persist Security Info=True;User ID=xxxx;Password=/*****/";
string connstring = "Data Source=192.168.1.1:1433 ; Network Library=DBMSSOCN; Initial Catalog=np-sparcsn4-custom;Persist Security Info=True;User ID=xxxx;Password=/*****/";
I've tried to replace the IP address with name - no luck. When I try to connect using the table adapter I can preview the data, same if I'd use i.e. grid - but in the code I simply can't open connection to it: I always have Network related or server specific error, usually its either
Named Pipes Provider: Could not open a connection to SQL Server [5]
or
provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server
Server is set up to accept remote connection and it is accessible.
Update:
I've tried
string connstring = "Server=tcp:192.168.1.1,1433 ;Initial Catalog=np-sparcsn4-custom;Persist Security Info=True;User ID=xxx;Password=/****/";
or
"Server=tcp:ponln4report,1433 ....
and I've got error:
provider: TCP Provider, error: 0 - A non-recoverable error occurred during a database lookup**strong text**
EDI2: I've found an older SQL server 2005 that I can connect without a problem. It is a bit of a pain because it lacks i.e. Date and Time data types, but I guess it has to do for now.
For C#, use this connection string
connectionString="Data Source=192.168.1.1,1433;Initial Catalog=np-sparcsn4-custom;Integrated Security=false;User ID=your_username;Password=your_password"
If you need to modify a web.config file, add this node:
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="Data Source=192.168.1.1,1433;Initial Catalog=np-sparcsn4-custom;Integrated Security=false;User ID=your_username;Password=your_password" providerName="System.Data.SqlClient" />
</connectionStrings>
Make sure port 1433 is set in IPALL in the SQL Configuration Manager -> Protocols for SQLEXPRESS
screenshot

Problems with connecting to local SQL Server Network Interfaces, error: 26

I'm currently trying to connect from Visual Studio 2013 C# application to a SQL Server 2012 instance but I'm running into troubles. Namely error 26 that no connection could be created.
My question there is what could still be wrong with what I'm doing (I'll post the code snippets I use below and then also what I controlled so far / steps I took):
Code
I created an application config which has the following line:
<connectionStrings>
<add name="DefaultConnectionString"
connectionString="Data Source=TH-HP\SQLEXPRESS;Initial Catalog=BB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False"
providerName="System.Data.SqlClient"/>
</connectionStrings>
I use an intermediary class I call Database to create the connection strings and run the commands.
When initializing it I use the following command (which sets the private variable connectionStr):
Database db = new Database(Properties.Settings.Default.ConnectionString);
Then when I try to open the connection:
SqlConnection con = new SqlConnection(this.connectionStr);
con.Open();
The error happens.
Steps
(as note both the program and the SQL Server instance are running on the same machine)
Correct servername
Correct catalogue name
SQL Server accepts remote connections
Server Browser is running
Server itself is running (connected to it via management console)
Like I said I'm running out of ideas what to check next.
this link may help: How to connect to local instance of SQL Server 2008 Express
also make a try with changing ConnectionString to:
<add name="DefaultConnectionString" connectionString="Data Source=TH-HP;Initial Catalog=BB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False" providerName="System.Data.SqlClient"/>
or
<add name="DefaultConnectionString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=BB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False" providerName="System.Data.SqlClient"/>

How to connect to SQL Server from a client machine?

Hello everybody i have a question and confusion about a project that i developed, and I will be very happy if you help me to improve my project.
I worked in VS2010 with C# and my database is attached in Sql Server 2008. my app is supposed to work in a LAN, so i'm thinking to make two versions of this app, the first will include the database and the sql server(plus the winforms of course), the second will just contain dotNet framework and it's supposed to connect to the database installed on the other machine. Is it possible. If so, how??
yes it is posible.
alter your connection string's "data source" to "ip address of the server"
Suppose in your machine where sql server is installed you are using this connection string
"data source=localhost;initial catalog=databasename;uid=sa;pwd=password"
then in the client system you need to alter it like this
"data source=IpAddressOfTheServer;initial catalog=databasename;uid=sa;pwd=password"
Note: the application having server's ip address in connection string is accessible by both, server and the client.
if Connection String in your (c# ) code Setted, Change connection string's "Data Source" to "IP address of server"
an another way change connection string in (App Config or WebConfig) at StartUp Project by below format:
<configuration>
<connectionStrings>
<add name="DB" connectionString="Data Source=192.168.10.5;
Initial Catalog=SafetyDB;Persist Security Info=True;User ID=sa;
Password=a1234$; connection timeout=5000" />
</connectionStrings>

Categories

Resources