I have write one .Net application in C# I use these strings to connect
str = "Data Source=200.1xx.2yy.1zz ;Initial Catalog =minofom;uid =sa;pwd = abuelita";
and the same string for app.config:
<add name="MiniFinan.Properties.Settings.MiniFimConnectionString"
connectionString="Data Source=200.1xx.2yy.1zz ;Initial Catalog =minofom;uid=sa;pwd = abuelita" providerName="System.Data.SqlClient" />
All the forms open fine, when I'm out of the local network, the app and the reports work perfect, but when I install the app in the server or any machine of the local network the app show me this error:
“Named Pipes Provider, error: 40 - Could not open a connection to SQL Server”
The local server is a domain controller, I use this string for local area network:
str="Data Source=192.168.2.254 ;Initial Catalog =MinoFom;uid =sa;pwd = abuelita"
All the forms work, but when I call to any report not connect, I use the same string for the app.config. I have tested the same app in other Server 2003 (not Domain Controller) and the reports works, have any way of write the string for domain, any idea of how to fix this?
I have checked SQL Browser is online, the protocols : Shared Memory/ Named Pipes/TCPIP are installed and work. I think is something with the domain.
I have solved using two strings one for the forms :
str = #"Data Source=TORRE ;Initial Catalog =minofom;uid =sa;pwd = abuelita";
and other in the app.config for the reports :
connectionString="Data Source=MyDomain\TORRE;Initial Catalog=MinoFom;uid =sa;pwd = abuelita"
Its posible save more than one string in app.config , enjoy
Related
I am trying to make a simple database application. It is just writing and reading from local database file using c# winform, but when i move the application folder to another pc, it comes with error. I thought it is just some dumb mistake with connstring or file accesses but when i click continue and the Application starts, there is even nothing loaded in combo boxes (which should be filled normally, without using any database stuff). Sorry for my English and thanks for response.
I cannot post image because i am new here but the exception says among other text this:
error 50 - local database runtime error occurred. The specified
LocalDB instance does not exist.
The solution really depends on what is your application's design.
Centralized Database:
If your application is supposed to use the centralized database - meaning multiple c# winform applications connect with same database.
Then you will have to make sure that the database server's IP address / machine name / Identifier is mentioned as "Data Source" in the connection string.
For ex. below connection string shows, how you will connect to database if windows authentication is to be used for connection. You will have to replace Data Source as your IP address and Initial Catalog with the database name
Data Source=your-server-address;Initial Catalog=your-database;Integrated Security=TRUE;
Local Database:
If your application is supposed to use local database i.e. for every c# winforms application user, there will be local database on his machine,
Then you will have to make sure that the required components (i.e. SQL Express, SQL or any other database server you want to use) are installed.
Hope this clarifies.
Check your LocalDB connection string and point it to the right file location as you can see below (taken from here). Its path is now different as you moved your application (AttachDBFilename attribute)
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=
(LocalDb)\MSSQLLocalDB;Initial Catalog=aspnet-MvcMovie-fefdc1f0-bd81-4ce9-b712-
93a062e01031;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-
MvcMovie-fefdc1f0-bd81-4ce9-b712-93a062e01031.mdf"
providerName="System.Data.SqlClient" />
</connectionStrings>
I have a winForm application which will be used by more than one persone, I want to put the database in a machine server so can everyone connect to it from this application.
I'm using SqlServer database, this database will be located in a local network.
This is the connection string I use to get data from a database located in my machine
string con = "Data Source=MSSQL1;Initial Catalog=AdventureWorks;Integrated Security=true;";
My question is what is the connection string that I should use to get data from database located in a machine server ?
Is it something like this ?
Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;
Thanks.
Without any specific information nobody will be able to answer this for you, however This Resource. might help you find it for yourself.
I have developed a web application in asp.net , and have published that website in iis 7.
I have given full access to the published folder and it works perfectly.When i browse my published application the login page has been loaded initially. If i fill the details and tried to login there connection fails.SQL connection has noot been opened
webConfig i have
<add name="SQLSERVER2008ConString" connectionString="Data Source=(local);Initial Catalog=REPOSITY;Integrated Security=True" providerName="System.Data.SqlClient"/>
and for opening connection
SqlConnection con = new SqlConnection(conString);
con.Open();
here the connection is not getting opened.But it works perfectly in my development environment.But not working after i published the code.
this how i connect my sql in local
Note:
Development environment is my system.
Used SQL Server 2008 and that is also in my system.
Published the website from my system only.
thanks
use this code
String conString= System.Configuration.ConfigurationManager.ConnectionStrings["SQLSERVER2008ConString"].ConnectionString;
SqlConnection con = new SqlConnection(conString);
con.Open();
Are you sure your SQL Local Login Name is (local) ? Check the name once. But If Yes, then try this: <add name="SQLSERVER2008ConString" connectionString="Data Source=(local);Initial Catalog=REPOSITY;Integrated Security=True" User Id = [ENTER YOUR WINDOWS LOGIN USERNAME];Password = [ENTER YOUR WINDOWS LOGIN PASSWORD]"/>
I have built a window form application and I use ADO.NET entity Data model to make connection with my local database and it work good with my own PC (the database and application in one PC).
Now I need the application to be used by many users 3 or 4. I have no idea how to install my database on the server and whether ADO.NET entity Data model will work again. I use SQL Server 2008 and C# window Form. Please I am waiting to hear what your suggestion will be.
all you need to do is just change the Data Source value in your connection string.
Follow the below Steps:
Step 1: Install and Maintain Your Database in your server machine.
Step 2 : Specify your databse Server HostName/IP Address in your Connection String as below:
String connectionString="Data Source=ServerName;Intial Catalog=DatabaseName;UID=userID;Password=password;Integrated Security=True;"
Add app.config file to your project and specify the connection string in there. Then access the config file using c#
<connectionStrings>
<add name="MyDBConnectionString" providerName="System.Data.SqlClient"
connectionString="Data Source=localhost;Initial Catalog=MySQLServerDB; Integrated Security=true" />
</connectionStrings>
in c#
System.Configuration.ConfigurationManager.ConnectionStrings["MyDBConnectionString"].ConnectionString;
Source Accessing database connection string using app.config in C# winform
You have host your database on server
Get server ip,username,password for the database
change your connection string
replace server name ,username,password
Data Source=serverip;Initial Catalog=dbname;Persist Security Info=True;User ID=username;Password=password
then this will be goto server database
currently I am using this connection string inside the app.config file of the application
add name="LightSailEntities" connectionString="metadata=res://*/LightSailEntities.csdl|res://*/LightSailEntities.ssdl|res://*/LightSailEntities.msl;provider=System.Data.SqlClient;provider connection string='data source=abc.xyz.com;initial catalog=LightSail;user id=LightSail; password=yourpasswordhere;MultipleActiveResultSets=True;App=EntityFramework'" providerName="System.Data.EntityClient"
The domain of .Net application and the domain of client, using .Net application, is different from domain of SQL server. I mentioned "using widows authentication" only because of, I have the access of the server machine(means I can use Remote Desktop Connection) on which the SQL server is installed.
For Windows Auth you don't need to set the User Id and Password but you do need to include 'Integrated Security=SSPI;'
Try:
add name="LightSailEntities" connectionString="metadata=res://*/LightSailEntities.csdl|res://*/LightSailEntities.ssdl|res://*/LightSailEntities.msl;provider=System.Data.SqlClient;provider connection string='data source=dev.shopcube.com;initial catalog=LightSail;Integrated Security=SSPI;MultipleActiveResultSets=True;App=EntityFramework'" providerName="System.Data.EntityClient"
There's a bit more info here:
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring(VS.71).aspx
You have to change ConnectionString to use Integrated Security=SSPI insetad of user and password
add name="LightSailEntities"
connectionString="metadata=res://*/LightSailEntities.csdl|res://*/LightSailEntities.ssdl|res://*/LightSailEntities.msl;
provider=System.Data.SqlClient;
provider connection string='data source=dev.shopcube.com;initial catalog=LightSail;Integrated Security=SSPI;MultipleActiveResultSets=True;App=EntityFramework'"
providerName="System.Data.EntityClient"
After that, look at the Identity set for the Application Pool of you application.
That user must be authorized to access your DB using Security\Logins inside Object Explorer pan of Management Studio.
Youo can use following code:
SqlConnection conn = new SqlConnection(Configuration.DBConn);
or if you use Linq2SQL:
DBContext ctx = new DBContext(Configuration.DBConn);
where in Configuration class DBConn string contains connection string to sql ie:
Data Source=XYZ\\DEV;Initial Catalog=YOURDB;Integrated Security=True;Connect Timeout=600;connection lifetime=600
Integrated Security=True tells that you want to use windows auth.